FP_MODBUS_MASTER

Write data to slave or read data from slave

Available function codes (with programming examples)

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

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.

Parameters

Input

Port (WORD, INT, UINT)

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

SlaveAddress (WORD, INT, UINT)

Station number of the slave (0–255)

Set to 1, if a SYS_ETHERNET_USER_CONNECTION_xx is applied to input Port

FunctionCode* (WORD, INT, UINT)

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

StartRegister (WORD, INT, UINT)

Starting address (0–65535). The address type depends on the command specified by FunctionCode*.

NumberOfRegisters* (WORD, INT, UINT)

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

MasterData (BOOL, INT, UINT, WORD, DINT, UDINT, DWORD, REAL, DATE, TOD, DT, STRING)

Source address on the master for the data to be written to the slave.

Output

Result (WORD, INT, UINT)
  • For FP7 only:
    • 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

  • For other PLCs: set to 0

Specification of partner station

Communication mode

When SCU or ET-LAN is used

MODBUS

1–247

NOTE

For connection via Modbus, specify "1". The destination is determined by the IP address.

Specification of starting address of the source data area

Communication mode

Address range

MODBUS

0–65535 (16#FFFF)

Specification of received data amount

Transfer method

Number of sent data

Commands to use

Word transmission

1–127 words

  • For reading WY and WR, use SYS_MODBUS_01_READ_COIL.

  • For reading WX, use SYS_MODBUS_02_READ_INPUT.

  • For reading DT, use SYS_MODBUS_03_READ_HOLDING_REGISTER.

  • For reading WL and LD, use SYS_MODBUS_04_READ_INPUT_REGISTERS.

Bit transmission

1–2040 bits

  • For reading Y and R, use SYS_MODBUS_01_READ_COIL.

  • For reading X, use SYS_MODBUS_02_READ_INPUT.

Sample program using SCU

  • 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).

Remarks

  • 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.

I/O allocation

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.

NOTE

The contacts are used for reading the operation status. Do not write to them with a user program.

Sample program using Ethernet

  • 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).

Remarks

  • 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.

Time chart

  1.  (1) Master communication clear-to-send flag,e.g. sys_bIsEthernetUserConnection1MasterCommunication
  2.  (2) Check that the master communication clear-to-send flag is TRUE and check that the master communication sending flag is FALSE
  3.  (3) Master communication sending flag, e.g. sys_bIsEthernetUserConnection1MasterCommunicationActive

    While sending: Master communication sending flag is TRUE

    Sending done: Master communication sending flag is FALSE

  4.  (4) Execute this instruction
  5.  (5) Master communication sending done flag, e.g. sys_bIsEthernetUserConnection1CommunicationError

    Normal completion: FALSE

    Abnormal completion: TRUE

  6.  (6) Send data
  7.  (7) Response reception processing

I/O allocation

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.

NOTE

The contacts are used for reading the operation status. Do not write to them with a user program.

Error flags

sys_bIsOperationErrorHold (turns to TRUE and remains TRUE)
  • 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.
sys_bIsOperationErrorNonHold (turns to TRUE for one scan)
  • 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.

Example

SYS_MODBUS_01_READ_COIL

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)

Example

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).

SYS_MODBUS_02_READ_INPUT

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:

  • X (Input)

Example

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).

SYS_MODBUS_03_READ_HOLDING_REGISTER

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:

  • DT (data registers)

Example

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.

SYS_MODBUS_04_READ_INPUT_REGISTERS

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)

Example

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.

SYS_MODBUS_05_FORCE_COIL

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)

Example

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

SYS_MODBUS_06_PRESET_REGISTER

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:

  • DT (data registers)

Example

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

SYS_MODBUS_15_FORCE_COILS

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)

Example

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).

SYS_MODBUS_16_PRESET_REGISTERS

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:

  • DT (data registers)

Example

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.

Modified on: 2024-03-06Feedback on this pagePanasonic hotline