Modbus TCP client

Available from firmware 2024.6

Modbus is a long-living communication standard in industrial automation. For some years now it has been developed communicate via TCP and meeting security needs.

There are different Modbus implementations available, e.g. as a function block in the PLCnext Store. But using a function block,  its instantiation is necessary for each Modbus connection and also for each function code call, so in a larger structure that gets confusing for developers soon. There are some other custom implementations, some programmed in high-level languages. 

And now there is a Modbus TCP client directly implemented into the Automation Runtime Platform (ARP) of PLCnext Technology, and configurable via the PLCnext Engineer programming software. The implementation depends on the libmodbus open source library, provided by libmodbus.org.

PLCnext Technology does not provide a Modbus TCP server solution itself so far, but there are plans for that in future.

Even an interface for RSC services to use ModBus TCP via high-level language programming has already been integrated but needs some more testing and documentation. Stay tuned for updates...

How to configure a Modbus communication

  • Import the PLCnext Engineer Modbus TCP client library:
    In the Component panel, right-click on the Libraries folder and select Add Library from the  context menu.
  • From the PLCnext Engineer directory that opens in the Windows Explorer, pick the Modbus library.
    ↪ The library is copied into your PLCnext Engineer project.
  • To assign the Modbus TCP client feature to your device, drag-and-drop that Modbus library from the right-side COMPONENT panel onto the controller in the left-side PLANT panel.
  • Click the Modbus TCP node in the PLANT panel and switch to the Modbus Device List tab in the working area.
  • Assign the IP addresses of the Modbus TCP gateways or servers you want to communicate to:

    The number of Modbus TCP servers depends on the PLCnext Control type running the client:
    PLCnext Control   maximum Modbus servers
    AXC F 1152 8
    AXC F 2152 16
    AXC F 3152 16
    RFC 4072S 16
    BPC 9102S 16
  • Click on a node for the Modbus gateway or server in the PLANT view.
  • Look at the Settings tab to check and change the default timing parameters for the server connection: 
    Swap bytes can be activated if necessary
    Protocol only TCP is available by now
    Port always 502
    Connection timeout specifies how long the client waits for a response in this cycle of establishing a connection before a new connection is possible
    Reconnection interval specifies how long to wait for a new attempt to establish a connection
    Response timeout specifies how quick the Modbus server should respond to the client's Modbus telegram; otherwise an error is issued to the diagnostic register
    Trigger rate Cycle time of the telegrams sent to the Modbus server

  • Switch to the Registers tab to set up the Modbus function codes (FC) and data types for your application, e.g.:

    ↪ The function codes are then connected to global variables which you can are also see listed at the bottom of the Data List tab as Process data items.
  • Once you have set function codes up in the above Registers tab, you can then work with these global variables in your automation programs.

Supported function codes

These are the Modbus function codes (FC) that are supported by the ModBus TCP client:

FC Description
1 Read Coils
Read Discrete Inputs
Read Multiple Registers
Read Inputs Registers
Write Coils
6 Write Single Register
15 Force Multiple Registers
16 Write Multiple Registers
23 Read/Write Registers

Features for troubleshooting

Diagnostic registers

The diagnostics register is read out and displayed in the PLCnext Engineer diagnostic view:

Note: The last entry in the above table, CONTROL_DIAG_STATISTIC, has a special feature, in addition to resetting the diagnostic register once: Using a specific bit combination, the user can also activate or deactivate the Modbus connection. This way, specific Modbus devices can be deactivated for troubleshooting.

This feature can also be useful in operation if you want to send a message only once and don't need a cyclic Modbus communication. 

Notifications

PLCnext Engineer users will also find the familiar built-in notifications which can contain plain text, such as "connection lost", "wrong Modbus address", or timeout messages.


• Published/reviewed: 2024-09-24   ☀  Revision 073 •