Modbus TCP / RTU over TCP

Modbus device registers right in the chat

Connect Modbus TCP devices to the AI agent: registers and coils by a tag map through an on-site gateway. The agent sums up a day by the hour and meter usage.

How the agent works with Modbus TCP

Data is read by the gateway: a program installed as a service on a computer or server on the site network that reaches the device over Modbus TCP, port 502, or a serial gateway in RTU over TCP mode. The connection takes the address, the unit id (1 by default) and a register map: one line per tag with a path, an address and a type, such as holding.100 float32. The gateway sends data out over outbound connections only.

Addresses count from zero, as in the request: register 40001 of a manual is holding.0, and 30010 is input.9. Values in 2 and 4 registers are read in the byte order of the device manual (ABCD, CDAB, BADC, DCBA), and a tag may set its own. Neighbouring tags of one area and one unit are read in one request, up to 125 registers or 2000 bits; the gap between tags is 0 by default, because an unmapped register gives the whole request an exception.

The driver only reads: of the Modbus functions it sends read coils, discrete inputs, holding and input registers (codes 1 to 4). It has no write or combined functions. A device exception marks the tags of that request bad with its code, and a busy answer skips one scan; other units behind the same gateway keep reading.

In RTU over TCP mode a frame has no transaction id, so the gateway keeps one request at a time and after a new connection waits one answer timeout so that a late answer to an earlier request does not reach a tag. A slow device gets pauses after connecting and between requests. If the link to the cloud drops, data piles up on the gateway's disk and arrives once it is back.

Integration scenarios

What is on the line now

The agent finds tags by path, such as line1/tank, and shows current values of registers and coils with their timestamp and whether they are fresh.

Daily summary

The agent takes the temperature, pressure or power history for a day and shows the minimum, maximum, average and last value per hour.

Usage from a meter

The agent takes a month of readings of a totalizing meter held in a register pair and works out the usage per day.

A task on a threshold

The agent sets up a task that fires when a tag goes past a threshold and stays there for a set time, not on every sample past it.

Tags with an exception

The agent names tags the device answered with an exception and its code, such as 0x02 (no such address) or 0x0B (the device behind a gateway did not answer).

Gaps in the data

The agent shows history intervals without samples and says whether the site gateway is online right now.

Modbus TCP examples

Modbus TCP
Frozen chats: click a question
Сколько воды ушло за октябрь?

За октябрь 1 860 м³, в среднем 60 м³ в сутки.

  • Больше всего 94 м³ 17 октября
  • В выходные расход падал до 25–30 м³

Показания беру из пары регистров счётчика по карте тегов и считаю разницу по дням.

How to connect

Before you connect

  • A Modbus TCP device or a serial gateway in transparent mode
  • Port 502 or the gateway's port open to the site gateway computer
  • A register map from the device manual: addresses, types, byte order
  • The unit id, if it is not 1
  • A computer on the site network for the gateway service
  • Server admits listed addresses only? Allow connections from 158.160.205.91 and 87.228.27.163.
  1. 1

    Choose the gateway's transmission mode

    tcp matches each reply by transaction ID. RTU cannot distinguish identical late replies; choose tcp if the gateway supports Modbus TCP.

  2. 2

    Keep one master on the RTU line

    rtu_over_tcp requires a serial gateway in transparent mode. Disconnect other masters and TCP clients that receive copies of the same stream.

FAQ

Add a gateway on the Gateways tab and install it as a service on a computer on the site network. In the connection enter the device address, such as tcp://10.0.12.5:502, the unit id, the byte order and a register map: one line per tag with a path, an address and a type, such as line1/tank/level holding.100 float32 unit=°C. Assign the connection to the gateway and it starts polling.

The tags of the register map: coils, discrete inputs, holding and input registers, integer and floating values up to 64 bits, single bits of a register and strings. For each tag the agent reads the current value with its timestamp, the history in intervals and raw samples.

No. The driver sends only the read functions 1 to 4 and has no write functions. The agent writes nothing to the device.

A number like 40001 counts from one, and its first digit names the area: 4 is holding, 3 is input. The address drops that digit and counts from zero: 40001 is holding.0, 30010 is input.9. A bit of a register follows a dot, such as holding.100.3.

Category
Equipment
Connection
API key

Connect Modbus TCP

Connecting takes a couple of minutes, and your data stays in your own systems.

Connect