Three specific communication functions are defined for sending and receiving data via a Modbus communication channel:
-
READ_VAR: To read variables
-
WRITE_VAR: To write variables
-
DATA_EXCH: To send Modbus requests to another device over the selected protocol
Reading or writing of variables are carried out by addressing following requests to the targeted slave device.
These requests use the READ_VAR, WRITE_VAR, and DATA_EXCH communication functions:
Modbus request
|
Function code
|
Communication function
|
Read bits
|
16#01 or 16#02
|
READ_VAR
|
Read words
|
16#03 or 16#04
|
READ_VAR
|
Write bits
|
16#0F
|
WRITE_VAR
|
Write words
|
16#10
|
WRITE_VAR
|
Other request
|
all
|
DATA_EXCH
|
NOTE: WRITE_VAR can be used in broadcast mode (READ_VAR can't be used in broadcast mode). In this case, the PLC doesn't receive a response. Sending a broadcast request resets the activity bit and the code 16#01 (Exchange stop on timeout) is returned into the second management word.
NOTE: The objects read by Modicon M340 PLC can be of the type and .In this case, READ_VAR function generates a Modbus request: FC 0x2 or 0x4. In a Quantum PLC, it allows accessing the Input Status or Input Status Registers.
More generally, it is possible to send any Modbus requests to a slave device by using the DATA_EXCH communication function.
There are two ways of programming that enable an exchange executed by the communication functions to be cancelled: