DW11SerModMa
D = Device(SERCOM)
W = Writing functions
The DW11SerModMa function simulates the Modbus MASTER Protocol through the use of a SERCOM device.
In particular the function sorts an array (named “Buffer” in the implementation example below) that must be declared by the user and passed to the function. This array will mirror faithfully the system address table in conjunction with the Qmove. The number of elements in this array must be at least equal to the number of the highest address of your device, plus one (for example, If the highest address between the variables you want to exchange is 600, the minimum size of the array must be of 601 items).
The choosing whether to execute a writing or reading on the Slave device, must be made by the user of the function through the setting of the “modWrite” variable.
The “address” variable should contain the address of the first variable in the group to read or write.
The “points” variable must contain the number of variables that you want to read or write to the following “address”.
The Modbus functions supported by the function are:
-
Function 3 - Read Holding Register (word reading)
-
Function 16 - Force Multiple Register (multiple word writing)
IMPLEMENTATION
DW11SerModMa (sercom1, Buffer, idcard, modWrite, address, points, error)
Parameters:
IN/OUT | VARIABLE TYPE | EXAMPLE NAME | DIM | |
---|---|---|---|---|
IN | INTDEVICE | sercom1 | - | Mnemonic name of SERCOM used |
IN | ARRSYS / ARRGBL | Buffer | W | Address Buffer |
IN | GLOBAL | idcard | W | Identification card. Is the number that identifies the device on the network. |
IN | GLOBAL | modWrite | F | Read/Write Mode. Discriminates if you want to execute a write or read on the Slave instrument. 0 = Reading 1 = Writing |
IN | GLOBAL | address | W | Address of the first variable in the group to read or write. |
IN | GLOBAL | points | L | Number of points (word) that you want to read or write starting from the “address”. |
OUT | GLOBAL | error | L | Variable containing the error code |
Error
After calling the function if there are any errors the error variable having the following values:
0 - No error
1 - Number char in reception > Buffer dimension (64 items). (Check on “Limits” section)
2 - Error Checksum
3 - Address > maximum size of user Buffer
4 - Number of bytes required to answer > 64 (maximum limit of the buffer device)
5 - Time Out: The slave does not respond within 200ms
6 - Function Type of mismatch response
7 - Number of characters in response does not match the expected number
Example
FILE.CNF
INTDEVICE ;Name Type dev. Tcamp. N°ser port N°item. Sercom1 SERCOM 0002 1 150
TASK_00
sercom1:mode = 0 sercom1:brate = 38400 sercom1:datab = 8 sercom1:stopb = 1 sercom1:par = 0 OPENCOM sercom1 WAIT sercom1:st_opencom gfIniz = 1
TASK_01
idcard = 1 MAIN: IF gfIniz ;----- READING -------- modWrite = 0 ;Set READING address = 20 ;Address variable to read points = 5 ;number word to read DW11SerModMa (sercom1, Buffer, idcard, modWrite, address, points, error) IF NOT error glVariabile1 = Buffer [20] ;Assigns the value read from Slave to the variable 1 glVariabile2 = Buffer [21] ;Assigns the value read from Slave to the variable 2 glVariabile3 = Buffer [22] ;Assigns the value read from Slave to the variable 3 glVariabile4 = Buffer [23] ;Assigns the value read from Slave to the variable 4 glVariabile5 = Buffer [24] ;Assigns the value read from Slave to the variable 5 ENDIF ;----- WRITING -------- Buffer [50] = cnCounter:posit ;Assign the count value at the address 50 modWrite = 1 ;Set READING address = 50 ;Address variable to written points = 1 ;number word to write DW11SerModMa (sercom1, Buffer, idcard, modWrite, address, points, error) ENDIF WAIT 1 JUMP MAIN END
Note
-
It is recommended that you implement the function in a specific task whereas the same contains instructions to WAIT that might block the Task itself.
Limits
Modbus functions supported by this function are:
-
Function 3 - Read Holding Register (word reading)
-
Function 16 - Force Multiple Register (multiple word writing)
The restriction on the number of variables that you can exchange is as follows
-
Function 3
-
maximum 30 word readable at the same time
-
Function 16 : maximum 28 word writable at the same time
-