en:software:qview:qview_6:qcl_library:dw14sermodsl

This translation is older than the original page and might be outdated. See what has changed.

DW14SerModSl

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:

  • Function 3 - Read Holding Register (word reading)
  • Function 16 - Force Multiple Register (multiple word writing)

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/OUTVARIABLE TYPEEXAMPLE NAMEDIM
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)

Example

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

Note

  • It is recommended that you implement the function in a task specific whereas the same contains instructions to WAIT that might block the Task.
  • If you want to increase the speed of data exchange you can set the “mode” parameter of the SERCOM device to the value “2” (only in the firmware that support this function of the device. If the value 2 of the parameter is not supported by the firmware, the “wdata” flag of the device is activated)

Limits

The restriction number of variables that you can exchange is as follows

  • Function 3 - Read Holding Register (word reading)
  • Funzione 16 - Force Multiple Register (multiple word writing)

The restriction number of variables that you can exchange are as follows:

  • Function 3
maximum 30 word readable at the same time
  • Function 16 : maximum 28 word writable drives simultaneously
  • Last modified: 2019/08/29 17:01