M241 Logic Controller as a Slave Device on Modbus TCP
This section describes the configuration of the M241 Logic Controller as a Modbus TCP Slave Device.
To configure your M241 Logic Controller as a Modbus TCP Slave Device, you must add Modbus TCP Slave Device functionality to your controller (see Adding a Modbus TCP Slave Device). This functionality creates a specific I/O area in the controller that is accessible with the Modbus TCP protocol. This I/O area is used whenever an external master needs to access the %IW and %QW objects of the controller. This Modbus TCP Slave Device functionality allows you to furnish to this area the controller I/O objects which can then be accessed with a single Modbus read/write registers request.
The Modbus TCP Slave Device adds another Modbus server function to the controller. This server is addressed by the Modbus client application by specifying a configured Unit ID (Modbus address) in the range 1...247. The embedded Modbus server of the slave controller needs no configuration, and is addressed by specifying a Unit ID equal to 255. Refer to Modbus TCP Configuration.
Inputs/outputs are seen from the slave controller: inputs are written by the master, and outputs are read by the master.
The Modbus TCP Slave Device can define a privileged Modbus client application, whose connection is not forcefully closed (embedded Modbus connections may be closed when more than 8 connections are needed).
The timeout duration associated to the privileged connection allows you to verify whether the controller is being polled by the privileged master. If no Modbus request is received within the timeout duration, the diagnostic information i_byMasterIpLost is set to 1 (TRUE). For more information, refer to the Ethernet Port Read-Only System Variables.
For further information about Modbus TCP, refer to the www.modbus.org website.
Adding a Modbus TCP Slave Device
Step |
Action |
---|---|
1 |
Add a TM4ES4 expansion module to your configuration. To do this, you must have added the Industrial_Ethernet_manager to your logic controller. |
2 |
Select Modbus TCP Slave Device in the Hardware Catalog. |
3 |
Drag and drop it to the Devices tree on one of the highlighted nodes. For more information on adding a device to your project, refer to: • Using the Drag-and-drop Method • Using the Contextual Menu or Plus Button |
To configure the Modbus TCP slave device, double-click Ethernet_1 > ModbusTCP_Slave_Device in the Devices tree.
This dialog box appears:
Element |
Description |
---|---|
IP Master Address |
IP address of the Modbus master The connections are not closed on this address. |
TimeOut |
Timeout in 500 ms increments NOTE: The timeout applies to the IP Master Address unless the address is 0.0.0.0. |
Slave Port |
Modbus communication port (502) |
Unit ID |
Sends the requests to the Modbus TCP slave device (1...247), instead of the embedded Modbus server (255). |
Holding Registers (%IW) |
Number of %IW registers to be used in the exchange (2...40) (each register is 2 bytes) |
Input Registers (%QW) |
Number of %QW registers to be used in the exchange (2...40) (each register is 2 bytes) |
Modbus TCP Slave Device I/O Mapping Tab
The I/Os are mapped to Modbus registers from the master perspective as follows:
o%IWs are mapped from register 0 to n-1 and are R/W (n = Holding register quantity, each %IW register is 2 bytes).
o%QWs are mapped from register n to n+m -1 and are read only (m = Input registers quantity, each %QW register is 2 bytes).
Once a Modbus TCP Slave Device has been configured, Modbus commands sent to its Unit ID (Modbus address) are handled differently than the same command would be when addressed to any other Modbus device on the network. For example, when the Modbus command 3 (3 hex) is sent to a standard Modbus device, it reads and returns the value of one or more registers. When this same command is sent to the Modbus TCP Slave, it facilitates a read operation by the external I/O scanner.
Once a Modbus TCP Slave Device has been configured, Modbus commands sent to its Unit ID (Modbus address) access the %IW and %QW objects of the controller instead of the regular Modbus words (accessed when the Unit ID is 255). This facilitates read/write operations by a Modbus TCP IOScanner application.
The Modbus TCP Slave Device responds to a subset of the Modbus commands with the purpose of exchanging data with the external I/O scanner. The following Modbus commands are supported by the Modbus TCP Slave Device:
Function Code Dec (Hex) |
Function |
Comment |
---|---|---|
3 (3) |
Read holding register |
Allows the master to read %IW and %QW objects of the device |
6 (6) |
Write single register |
Allows the master to write %IW objects of the device |
16 (10) |
Write multiple registers |
Allows the master to write %IW objects of the device |
23 (17) |
Read/write multiple registers |
Allows the master to read %IW and %QW objects of the device and write %IW objects of the device |
Other |
Not supported |
– |
NOTE: Modbus requests that attempt to access registers above n+m-1 are answered by the 02 - ILLEGAL DATA ADDRESS exception code.
To link I/O objects to variables, select the Modbus TCP Slave Device I/O Mapping tab:
Channel |
Type |
Description |
|
---|---|---|---|
Input |
IW0 |
WORD |
Holding register 0 |
... |
... |
... |
|
IWx |
WORD |
Holding register x |
|
Output |
QW0 |
WORD |
Input register 0 |
... |
... |
... |
|
QWy |
WORD |
Input register y |
The number of words depends on the Holding Registers (%IW) and Input Registers (%QW) parameters of the Modbus TCP tab.
NOTE: Output means OUTPUT from Originator controller (%IW for the controller). Input means INPUT from Originator controller (%QW for the controller).
NOTE: The Modbus TCP slave device refreshes the %IW and %QW registers as a single time-consistent unit, synchronized with the IEC tasks (MAST task by default). By contrast, the embedded Modbus TCP server only ensures time-consistency for one word (2 bytes). If your application requires time-consistency for more than one word (2 bytes), use the Modbus TCP Slave Device.
Select the Bus cycle task to use:
oUse parent bus cycle setting (the default),
oMAST
There is a corresponding Bus cycle task parameter in the I/O mapping editor of the device that contains the Modbus TCP slave device. This parameter defines the task responsible for refreshing the %IW and %QW registers.