The following example shows you how to use the
SEND_REQ function block to send a Modbus Write Multiple Registers explicit message that will write two (2) registers to a remote device at IP address 192.168.1.6, starting at register address 10 in the remote device.
NOTE: This request is simpler in its configuration than, for example, the
generic Modbus write registers request. The ReqCode setting specifies the function, so no additional Modbus function code is required.
Implementing the SEND_REQ Function Block
To implement the SEND_REQ function block, you need to create and assign variables for the following blocks:
Configuring the Address Variable
The Address variable identifies the explicit message originating device—-in this example, the TSX ETC 101 communication module—and the target device. Note that the Address variable does not include the Xway address elements {Network.Station} because we are not bridging through another PLC station. Use the ADDR function to convert the following character string to an address:
ADDR(‘0.3.0’), where:
-
rack = 0
-
module (slot number) = 3
-
channel = 0
Configuring the ReqCode Variable
The ReqCode variable identifies the function type for the SEND_REQ function block—in this case, a Modbus Write Multiple Registers request:
Variable
|
Description
|
Value (hex)
|
ReqCode
|
Modbus Write Multiple Registers request
|
16#0052
|
Configuring the ManagParam Variable
The ManagParam[3] setting defines the length of the DataToSend variable for the SEND_REQ function block. In this example, 12 bytes of data will be sent:
Variable
|
Description
|
Value (hex)
|
ManagParam[3]
|
Length of the DataToSend variable
|
16#000C
|
Configuring the DataToSend Variable
The DataToSend variable defines the data to be sent in the Modbus Write Multiple Registers request:
Variable
|
Description
|
Value (hex)
|
DataToSend[0]
|
First two octets of the target device IP address (192.168.1.6):
|
16#C0A8
|
DataToSend[1]
|
Last two octets of the target device IP address (192.168.1.6):
|
16#0106
|
DataToSend[2]
|
|
16#000A
|
DataToSend[3]
|
|
16#0002
|
DataToSend[4]
|
|
16#AABB
|
DataToSend[5]
|
|
16#CCDD
|