Write data to slave or read data from slave
Available function codes (with programming examples)
SYS_MODBUS_03_READ_HOLDING_REGISTER
SYS_MODBUS_04_READ_INPUT_REGISTERS
SYS_MODBUS_16_PRESET_REGISTERS
Use this instruction to write data from a master to a slave or read data from a slave via the communication port using the Modbus RTU protocol, as defined in the system registers of the port used. Make sure the same protocol is set for master and slave.
Input
Specifies the communication ports depending on the PLC type:
COM port e.g. SYS_COM0_PORT
Ethernet port e.g. SYS_ETHERNET_USER_CONNECTION_1
MCU/SCU e.g. 16#xx01 (xx = slot number) in COM01
Station number of the slave (0–255)
Set to 1, if a SYS_ETHERNET_USER_CONNECTION_xx is applied to input Port
SYS_MODBUS_01_READ_COIL
SYS_MODBUS_02_READ_INPUT
SYS_MODBUS_03_READ_HOLDING_REGISTER
SYS_MODBUS_04_READ_INPUT_REGISTERS
SYS_MODBUS_05_FORCE_COIL
SYS_MODBUS_06_PRESET_REGISTER
SYS_MODBUS_15_FORCE_COILS
SYS_MODBUS_16_PRESET_REGISTERS
Starting address (0–65535). The address type depends on the command specified by FunctionCode*.
Number of transmission bits or words.
1–2040 for function codes 01, 02
2–2040 for function code 15
1–127 for function codes 03, 04
2–127 for function code 16
Source address on the master for the data to be written to the slave.
Output
0: Normal completion
1: Communication port is used for master communication
2: Communication port is used for slave communication
3: No. of master communication instructions that can be used at the same time is exceeded
4: Sending timeout
5: Response reception timeout
6: Received data error
Communication mode |
When SCU or ET-LAN is used |
---|---|
MODBUS |
1–247 |
For connection via Modbus, specify "1". The destination is determined by the IP address.
Communication mode |
Address range |
---|---|
MODBUS |
0–65535 (16#FFFF) |
Transfer method |
Number of sent data |
Commands to use |
---|---|---|
Word transmission |
1–127 words |
|
Bit transmission |
1–2040 bits |
|
Send the command from the COM1 port of the CPU unit, read data from the data areas DT400–DT401 of the external device (Station No. 1), and write into PLC's data registers DT100–DT101.
Check that the master communication clear-to-send flag is TRUE (XC), and that sending is not in progress in the same port (YC), and execute the SEND instruction.
To execute the RECV instruction, specify the partner station no. (U1), starting address (DT400), data amount (U2), and PLC's starting address to store the data (DT100).
Master communication is only enabled when MEWTOCOL or MODBUS is selected. Check that the master communication clear-to-send flags (XC–XE) are TRUE for the corresponding channel, and execute the SEND/RECV instruction.
Another SEND/RECV instruction cannot be executed for a communication port where master communication is in progress. Check that the master communication sending flags (YC–YE) are FALSE and execute the instruction.
A SEND/RECV instruction cannot be executed for a port where slave communication is in progress.
If there is no response, the master communication sending flags (YC–YE) remain TRUE during the timeout period set in the CPU configuration.
Up to 16 SEND/RECV instructions can be executed simultaneously for different COM ports.
COM port No. |
Name |
Explanation |
||
1 |
2 |
0 |
||
XC |
XD |
XE |
Master communication clear-to-send flag |
Turns to TRUE when MEWTOCOL-COM, MEWTOCOL7 or MODBUS-RTU are set as communication mode, and the PLC is in RUN mode. |
YC |
YD |
YE |
Master communication sending flag |
Turns to TRUE while data is being sent by the SEND and RECV instructions. Turns to FALSE when sending is completed. |
Y0 |
Y1 |
Y2 |
Master communication sending done flag |
Turns to TRUE when sending by program controlled communication or master communication completed normally and turns to FALSE when sending completed abnormally. |
The contacts are used for reading the operation status. Do not write to them with a user program.
Send the command from the LAN port of the CPU unit, read data from the data areas DT400–DT401 of the external device, and write into PLC's data registers DT100–DT101.
Check that the master communication clear-to-send flag for connection 1 is TRUE (X90), and that sending is not in progress in the same port (Y90), and execute the sending instruction.
To execute the RECV instruction, specify the partner station no. (U1), starting address (DT400), data amount (U2), and PLC's starting address to store the data (DT100).
Master communication is only enabled when MEWTOCOL or MODBUS is selected. Check that the master communication clear-to-send flags (X90–X9F) are TRUE for the corresponding connection, and execute the SEND/RECV instruction.
Another SEND/RECV instruction cannot be executed for a connection where master communication is in progress. Check that the master communication sending flags (Y90–Y9F) are FALSE, and execute the instruction.
A SEND/RECV instruction cannot be executed for a connection where slave communication is in progress.
Up to 16 SEND/RECV instructions can be executed simultaneously for different ports.
For communication between LAN ports of FP7, specify "U1" for the partner station no. The destination is determined by the IP address.
While sending: Master communication sending flag is TRUE
Sending done: Master communication sending flag is FALSE
Normal completion: FALSE
Abnormal completion: TRUE
I/O number |
Name |
Explanation |
X90–X9F |
Master communication clear-to-send flag |
Turns to TRUE when MEWTOCOL-COM, MEWTOCOL7 or MODBUS-RTU are set as communication mode, and the PLC is in RUN mode. |
Y90–Y9F |
Master communication sending flag |
Turns to TRUE while data is being sent by the SEND and RECV instructions. Turns to FALSE when sending is completed. |
Y70–Y7F |
Master communication sending done flag |
Turns to TRUE when sending by program controlled communication or master communication completed normally and turns to FALSE when sending completed abnormally. |
The contacts are used for reading the operation status. Do not write to them with a user program.
When you apply this constant to the input parameter FunctionCode*, the corresponding Modbus command is executed.
For the special case that the connected slave is a Panasonic PLC configured as Modbus RTU slave via system register, one or multiple bits are read from:
Y (Output)
R (Internal flags)
Executing Modbus command 01: reads 1 bit from a Modbus slave beginning at start register 56 set by the variable StartRegister. Then the command stores the 1 bit in the master beginning at the address set by the variable bBool2. The slave's address is converted to a device-specific address depending on the Modbus specifications of the device.
If the connected slave is a Panasonic PLC, the start register 56 corresponds to output Y38 (3*16+8=56).
When you apply this constant to the input parameter FunctionCode*, the corresponding Modbus command is executed.
For the special case that the connected slave is a Panasonic PLC configured as Modbus RTU slave via system register, one or multiple bits are read from:
Executing Modbus command 02: reads 1 bit from a Modbus slave beginning at start register 66 set by the variable StartRegister. Then the command stores the 1 bit in the master beginning at the address set by the variable bBool2. The slave's address is converted to a device-specific address depending on the Modbus specifications of the device.
If the connected slave is a Panasonic PLC, start register 66 corresponds to input X42 (4*16+2=66).
When you apply this constant to the input parameter FunctionCode*, the corresponding Modbus command is executed.
For the special case that the connected slave is a Panasonic PLC configured as Modbus RTU slave via system register, one or multiple bits are read from:
Executing Modbus command 03: reads 2 words from a Modbus slave beginning at start register 100 set by the variable StartRegister. Then the command stores the 2 words in the Modbus master 2 beginning at the address set by the variable rCount2. The slave's address is converted to a device-specific address depending on the Modbus specifications of the device.
If the connected slave is a Panasonic PLC, start register 100 corresponds to data register DDT100.
Maximum number of registers: 127.
When you apply this constant to the input parameter FunctionCode*, the corresponding Modbus command is executed.
For the special case that the connected slave is a Panasonic PLC configured as Modbus RTU slave via system register, one or multiple bits are read from:
WL0–WL127 (Link flags)
LD0–LD256 (Link registers)
Executing Modbus command 04: reads 7 words from a Modbus slave beginning at start register 2018 set by the variable StartRegister. Then the command stores the 7 words in the master beginning at LD25 set by the variable MasterData. The slave's address is converted to a device-specific address depending on the Modbus specifications of the device.
If the connected slave is a Panasonic PLC, start register 2018 corresponds to link register LD18.
Maximum number of registers: 127.
When you apply this constant to the input parameter FunctionCode*, the corresponding Modbus command is executed.
In case the connected slave is a Panasonic PLC in Modbus RTU mode, one or multiple bits are written to:
Y (Output)
R (Internal flags)
Executing Modbus command 05: writes 1 bit to a Modbus slave beginning at address WY1 set by the variable MasterData. Then the command stores the 1 bit in a Modbus slave beginning at start register 35 set by the variable StartRegister. The slave's address is converted to a device-specific address depending on the Modbus specifications of the device.
If the connected slave is a Panasonic PLC, address 35 corresponds to output Y23 (2*16+3=35).
When writing multiple bit data use the SYS_MODBUS_15_FORCE_COILS Function Code
Maximum number of register: 1
When you apply this constant to the input parameter FunctionCode*, the corresponding Modbus command is executed.
In case the connected slave is a Panasonic PLC in Modbus RTU mode, one or multiple bits are written to:
Executing Modbus command 06: writes 1 word to a Modbus slave beginning at address DT14 set by the variable MasterData. Then the command stores the 1 word in the Modbus slave beginning at start register 21 set by the variable StartRegister. The slave's address is converted to a device-specific address depending on the Modbus specifications of the device.
If the connected slave is a Panasonic PLC, start register 21 corresponds to data register DT21.
When writing multiple bit data use the SYS_MODBUS_15_FORCE_COILS Function Code
Maximum number of register: 1
When you apply this constant to the input parameter FunctionCode*, the corresponding Modbus command is executed.
In case the connected slave is a Panasonic PLC in Modbus RTU mode, one or multiple bits are written to:
Y (Output)
R (Internal flags)
Executing Modbus command 15: writes 64 bits to a Modbus slave beginning at address WY1 set by the variable MasterData. Then the command stores the 64 bits in the Modbus slave beginning at start register 48 set by the variable StartRegister. The slave's address is converted to a device-specific address depending on the Modbus specifications of the device.
If the connected slave is a Panasonic PLC, address 48 corresponds to output Y30 (3*16=48).
When you apply this constant to the input parameter FunctionCode*, the corresponding Modbus command is executed.
In case the connected slave is a Panasonic PLC in Modbus RTU mode, one or multiple bits are written to:
Executing Modbus command 16: writes data to a Modbus slave beginning at the address set by the variable rCount1. Then the command stores the data in the Modbus slave 2 beginning with start register 100 set by the variable StartRegister. The slave's address is converted to a device-specific address depending on the Modbus specifications of the device.
If the connected slave is a Panasonic PLC, start register 100 corresponds to data register DDT100.
Maximum number of registers: 127.