4.5Modbus TCP
Read Modbus devices over the network by IP address and port, with their own unit id, timeout and retries.
The Modbus TCP interface lets the gateway read devices that are on the network instead of on a serial line: inverters, energy meters, PLCs and Ethernet-to-Modbus gateways. You give each device its IP address (Host), its TCP port (usually 502) and a Unit ID, then define its datapoints exactly as for an RS485 device.
#What it does
The gateway is the Modbus master. For every enabled TCP device it opens one connection, asks for each datapoint in turn, decodes the answer and publishes it as a value, optionally to a KNX group address. Several devices can be polled at the same time, each over its own connection. If a device stops answering or the cable is unplugged, the gateway reconnects on the next poll by itself.
#Open it
Select Server in the right-hand panel and open Interfaces > Modbus TCP.
| Property | What it does |
|---|---|
| Enabled | Turns Modbus TCP polling on or off for the whole project. Off by default. |
| Label | A name for the interface in the Configurator. The gateway does not use it. |
| Configure Devices (N) | Opens the device dialog. N is the number of devices. |
#The device dialog
Configure Modbus TCP Devices is the same dialog as for RS485, with these differences. Add a device with Add, name it, and fill in:
| Property | What it does |
|---|---|
| Host (IP address or name) | The device's address on the network, for example 192.168.1.50. A device without a host is not polled. |
| TCP port | The port the device listens on. Default 502. |
| Unit ID (0-255) | The Modbus unit identifier. Most devices use 1. Many Ethernet gateways and PLCs answer on 0 or 255, and a gateway in front of RS485 devices uses it to choose the slave behind it. |
| Timeout (ms) | How long to wait for an answer. 100 to 30000, default 1000. The same value limits how long the gateway waits to connect. |
| Retries | Extra attempts after a timeout or a dropped connection, before the value is marked stale. 0 to 10, default 2. A Modbus exception answer from the device is final and is not retried. |
| Enabled | A switch to stop polling one device without deleting it. |
The protocol driver, datapoints, scaling, word order and KNX publishing are the same as for RS485. See Modbus devices and datapoints for datapoint fields and the device profiles.
Test Read on a datapoint asks the gateway to read that register right now. For a TCP device the request carries the host and port, so you can test before the project is deployed. Fill in Host first.
#How it behaves
- Datapoints are polled every two seconds by default, one request each. A device that does not answer does not hold up the others.
- A value that cannot be read is shown as stale with the last known value; it recovers on the next successful read.
- A TCP device that is offline when you deploy does not make the deploy fail. The deploy only reports a serial bus that cannot be opened.
- The AC, Genset, UPS and Solar managers can use a Modbus TCP device: pick it in the manager's device list, where it is shown with its host.
- Reads use functions 01 to 04. The managers write with functions 06 and 10 as they do on RS485.
#Example
An energy meter with an Ethernet port:
- Server > Interfaces > Modbus TCP, switch Enabled on, click Configure Devices.
- Add, name
Grid Meter, Host192.168.1.50, TCP port502, Unit ID1, Timeout1000, Retries2. - Edit the starter datapoint: Address
0x0000, Read function3, Data typefloat32, Registers2, UnitW. Use the addresses from the meter's own manual. - Click Test Read. The result shows the registers and the raw frame.
- Deploy. The value is listed under System Value > Modbus TCP as
modbus:grid_meter.<datapoint>, ready for an Analog Value or the Power Flow Panel.
#Tips and common problems
- Test Read says it could not connect: check the IP address, that the gateway and the device are on the same network, and that the device's Modbus TCP server is switched on. Some devices only allow one TCP client at a time; close any other Modbus software that is connected to it.
- Test Read times out: the device is reachable but does not answer this unit id or register. Try Unit ID
0,1or255, and check the register address and function in the manual. - An exception answer: the device refused the request. Code 2 means the address does not exist, 3 a bad count or value, 11 that the gateway behind it could not reach the slave.
- Values go stale now and then: raise Timeout, or give the device a fixed IP address so the connection does not drop.
- Several devices behind one Ethernet gateway: add each one as its own device with the same Host and TCP port and a different Unit ID.