D = Device(SERCOM)
W = Writing functions
The DW14SerModSl function simulates the Modbus SLAVE 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 address table in conjunction with the Qmove device. The number of elements in this array must be at least equal to the number of the highest address of your device (for example, If the highest address between the variables you want to exchange is 600, the minimum size of the array must be of 600 items).
Modbus functions supported by this function are:
If you want to increase the speed of data exchange you can set the “mode” parameter of the SERCOM device to value “2” (only in the firmware that support this function of the device)
DW14SerModSl (Sercom1, Buffer, idcard, slrdelay, gfWrite, glError)
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. It's the number that identifies the device on the network. |
IN | SYSTEM | slrdelay | L | It's the time to wait before transmitting the reply. |
OUT | GLOBAL | gfWrite | F | Signal flag writing. When it is in State 1 means that the Master made a writing. |
OUT | GLOBAL | glError | L | Variable containing the error code |
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 (max limit of the device buffer)
5: Function Type Modbus not manage by the function (other than 3 or 16)
FILE.CNF
INTDEVICE ;Nome Type dev. Tcamp. N°serial port N°elem. Sercom1 SERCOM 0002 1 64
TASK_00
sercom1:mode = 0 sercom1:brate = 38400 sercom1:datab = 8 sercom1:stopb = 1 sercom1:par = 0 slrdelay = 0 OPENCOM sercom1 WAIT sercom1:st_opencom gfIniz = 1
TASK_01
Idcard = 1 MAIN: IF gfIniz Buffer [20] = cnCounter:posit ;Assign the count value to address 20 DW14SerModSl (Sercom1, Buffer, idcard, slrdelay, gfWrite, glError) IF gfWrite ;When writing the Master, gfWrite = 0 cnCounter:posit = Buffer [20] ;assigns the address value 20 to the counter ENDIF ENDIF END
The restriction number of variables that you can exchange is as follows
The restriction number of variables that you can exchange are as follows: