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.
Instead of using this F instruction, we recommend using the corresponding FP7 instruction: FP_MODBUS_MASTER
In contrast to other F145 or F146 instructions, the required Modbus command can directly be set by the parameter FunctionCode*.
The F145 or F146 instructions can only be executed if neither instruction is active. Evaluate the "F145/F146 not active" flag in your program to check the state of the instructions.
The F145 instruction only requests that data be sent to the slave. The actual processing takes place at the end of the scan.
Evaluate the "F145/F146 error" flag to check whether transmission has completed normally or with an error.
When broadcasting (SlaveAddress set to 0), make sure transmission is executed only after the maximum scan time has elapsed.
The F145 or F146 instructions cannot be executed if the destination address is a special internal flag (from R9000), a special data register (from DT9000/DT90000), or a file register FL.
Commands supported by the master:
Function code |
System constant |
Start register |
Number of registers |
Reference numbers (depending on Modbus slave) |
---|---|---|---|---|
01 |
SYS_MODBUS_01_READ_COIL |
0–65535 |
1–2040 |
000001–065536 |
02 |
SYS_MODBUS_02_READ_INPUT |
0–65535 |
1–2040 |
100001–165536 |
03 |
SYS_MODBUS_03_READ_HOLDING_ REGISTER |
0–65535 |
1–127 |
400001–465536 |
04 |
SYS_MODBUS_04_READ_INPUT_ REGISTERS |
0–65535 |
1–127 |
300001–365536 |
5 |
SYS_MODBUS_05_FORCE_COIL |
0–65535 |
1 |
000001–065536 |
6 |
SYS_MODBUS_06_PRESET_ REGISTER |
0–65535 |
1 |
400001–465536 |
15 |
SYS_MODBUS_15_FORCE_COILS |
0–65535 |
2–2040 |
000001–065536 |
16 |
SYS_MODBUS_16_PRESET_ REGISTERS |
0–65535 |
2–127 |
400001–465536 |
Modbus specifications for Panasonic PLCs:
Modbus area address |
Modbus memory name |
Memory type |
Panasonic PLCs address |
---|---|---|---|
000001 … |
COIL |
1-bit |
Y0 … |
002049 … |
R0 … |
||
100001 … |
INPUT |
1-bit |
X0 … |
400001 … |
HOLDING_REGISTER |
16-bit |
DT0 … |
300001 … |
INPUT_REGISTERS |
16-bit |
WL0 … |
302001 … |
LD0 … |
For reference number and address area ranges supported by the Panasonic PLCs, please refer to the User's Manual of the PLC. If the reference number is outside the supported range, an error is returned.
FP-X0, Multi-Communication Unit: Please refer to the corresponding manual that you can find in the download center in the Internet.
If slave or master data exceed the available address range.
If the communication mode is not set to MEWTOCOL-COM Master/Slave or Modbus RTU Master/Slave.
If the COM port selected requires a communication cassette that has not been installed.
If slave or master data exceed the available address range.
If the communication mode is not set to MEWTOCOL-COM Master/Slave or Modbus RTU Master/Slave.
If the COM port selected requires a communication cassette that has not been installed.
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 with 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 constant.
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 constant.
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.