To connect an energy analyser, drive or old PLC speaking Modbus RTU over RS-485 to SCADA, you put a gateway in between; it reads fine on the first day, and a week later complaints of intermittent “timeouts” and missing data begin. The cause is usually not in the device but in the setup: the wrong gateway mode, a shifted Unit ID mapping, poll times that exceed the capacity of the serial line, or several clients loading the same line. Below, we describe the gateway architecture, the timing calculation and step-by-step troubleshooting with exception codes.
Frame differences between Modbus RTU and Modbus TCP
The application data of the two protocols (PDU: function code and data) is the same. The difference lies in how this data is packaged.
| Field | Modbus RTU | Modbus TCP |
|---|---|---|
| Addressing | Slave address (1 byte, 1–247) | IP address + Unit ID (1 byte) |
| Item | None | MBAP header (7 bytes) |
| Error checking | CRC-16 (2 bytes) | None (provided by TCP) |
| Frame delimiting | At least 3.5 characters of silence | MBAP length field |
| Concurrency | A single master on the line, one pending request | Multiple clients and connections |
| Port | RS-485/RS-232 | TCP 502 |
The MBAP header consists of the transaction identifier (Transaction ID, 2 bytes), protocol identifier (2 bytes, 0 for Modbus), length (2 bytes) and Unit ID (1 byte) fields. The transaction identifier lets the TCP client match several requests over the same connection. RTU has no such field, because only one request can be pending on a serial line at a time. This is why the gateway has to manage a queue. The official source for the specifications is the Modbus Organization website.
Gateway architectures and operating modes
Serial-to-Ethernet converters on the market can operate in three different modes, and these modes are often confused:
| Mode | What it does | When |
|---|---|---|
| Modbus TCP ↔ RTU conversion | Removes the MBAP, adds the CRC; reverses this for the response | The right choice for standard Modbus TCP clients |
| RTU over TCP | Carries the RTU frame (including CRC) unchanged inside TCP | Only if the client software explicitly supports this mode |
| Transparent (serial tunnel) | Forwards bytes without knowing the protocol; virtual COM port | Legacy serial software, non-Modbus protocols |
A common installation mistake: connecting a standard Modbus TCP client to a gateway running in “RTU over TCP” or transparent mode. The connection is established, ping works, the port looks open; but the responses cannot be decoded and the client reports only timeouts. The network is fine; the mode is wrong. RTU over TCP is not a transport defined in the Modbus specification; interoperability depends on the manufacturer. In transparent mode, timeout and frame boundary handling are left entirely to the client software, and network latency can break RTU’s 3.5-character rule.
When choosing a gateway, besides mode support, look at the number of simultaneous TCP connections, request queue behaviour, configurable timeout per serial port and diagnostic counters (timeouts, CRC errors, exception counts). A gateway without diagnostic counters tells you nothing during a fault. If protocol conversion is part of the data collection architecture, the article edge gateway selection criteria offers a broader framework.
Unit ID and slave address mapping
Behind the gateway there is a single RS-485 line with several devices on it. The TCP client reaches all devices through the same IP address; the Unit ID in the MBAP determines which device the request goes to. In standard conversion mode, the gateway uses the Unit ID directly as the slave address on the serial line: a request arriving with Unit ID 5 goes to address 5 on the RTU line.
Where we get stuck with the mapping:
- Unit ID 0: This is the broadcast address on a serial line; broadcast requests receive no response. Some gateways reserve 0 for their own internal registers. Do not use it for read requests.
- Unit ID 255: The Modbus TCP implementation guide recommends using 0xFF for direct TCP devices that are not behind a gateway. Some TCP devices, however, ignore the Unit ID or accept only a specific value; check the device documentation.
- Address conflicts: If two devices on the same RS-485 line have the same address, their responses collide and CRC errors occur. Before migrating, compile the address list for each line.
- Multiple serial ports: On two-port gateways, which Unit ID range is routed to which port is defined in a mapping table; the same address existing on both ports causes problems without this table.
Another source of confusion is register addressing. A holding register shown as “40001” in documentation corresponds to address 0 in the protocol. A single offset error makes the data read one register off; because the values look plausible, it may go unnoticed for months. During commissioning, verify the mapping by reading a known value (for example the device’s serial number or a fixed parameter). Don’t guess; read.
Timing: poll time, timeout and RS-485 line speed
In RTU, one character consists of 11 bits (1 start, 8 data, 1 parity and 1 stop bit; 2 stop bits if parity is not used). The serial line time can therefore be calculated directly. The values below are an example calculation based on assumptions:
Line speed : 9600 bit/s
1 character : 11 / 9600 ≈ 1.15 ms
Inter-frame gap : 3.5 characters ≈ 4 ms
Reading 10 holding registers with FC03:
Request : 8 bytes → 8 × 1.15 ≈ 9.2 ms
Response: 25 bytes → 25 × 1.15 ≈ 28.8 ms
Gaps (2 × 4 ms) ≈ 8 ms
Device response time (assumed) ≈ 20 ms
Total ≈ 66 ms
One round on a 10-device line ≈ 660 ms
Same line at 19200 bit/s ≈ 430 ms (device response time unchanged)
This is an example calculation, not a field measurement; real times must be measured according to the device’s response time. Three practical conclusions follow from the calculation. First, the capacity of the serial line is limited; if the client’s poll time is set shorter than the time the line needs to complete one round, requests pile up in the gateway queue and latency keeps growing. The queue does not empty by itself. Second, increasing the line speed only shortens transmission time; the device’s own response time stays the same. Third, reading consecutive registers in a single request is far more efficient than sending many small requests: a single FC03 can read up to 125 registers.
Set timeouts in layers. The gateway’s serial-side timeout must cover the response time of the slowest device; the TCP client’s timeout must be longer than the gateway timeout × number of retries plus the time spent waiting in the queue. If the client timeout is shorter than the gateway’s, the old response comes back while the client is cancelling the request and sending a new one; with clients that do not match Transaction IDs correctly, responses get mixed up, and with those that do, unnecessary retries load the serial line even more. At speeds above 19200 bit/s, the specification recommends a fixed value of 1.75 ms for the 3.5-character gap.
The RS-485 physical layer also affects timing: 120 Ω termination at both ends of the line, biasing at a single point, a bus (not star) topology and a limit of 32 devices per segment at standard unit load. On long lines with missing termination, reflections show up as CRC errors and increase the gateway’s diagnostic counters. The source of a fault being hunted in software is sometimes a missing resistor.
Simultaneous connection limits and the multi-master problem
On the Modbus TCP side, SCADA, a historian, energy management software and an engineering tool can all connect to the same gateway at the same time. The serial side, however, works with a single master: the gateway queues all requests and sends them one by one. This has two consequences:
- When the gateway’s simultaneous TCP connection limit is exceeded, new connections are refused or old connections are closed. This limit varies from device to device and is stated in the datasheet; “half-open” connections that never close can fill up the limit, so check the clients’ keep-alive and reconnect behaviour.
- Every new client shares the serial line’s capacity. If three clients read the same devices once a second, the line carries three times the load. The lasting solution is to have a single data collector read the serial line and the other systems get the data from this collector (for example via OPC UA or MQTT), or to set separate poll times for each client deliberately.
Forgetting an old HMI or PLC still connected as a master on the same RS-485 line alongside the gateway causes the two masters to corrupt each other’s frames. The symptom is random CRC errors and intermittent timeouts. When migrating to Ethernet-based industrial network infrastructure, the gateway must be the line’s only master. The old master is removed.
Troubleshooting with exception codes
When a device understands a request but cannot carry it out, it returns an exception code by setting the highest bit of the function code to 1 (e.g. 0x83 instead of 0x03). Two gateway-specific codes are especially valuable for telling whether the problem is on the serial side or the TCP side:
| Code | Meaning | Typical cause |
|---|---|---|
| 01 | Illegal Function | The device does not support this function code |
| 02 | Illegal Data Address | The register address does not exist, or an offset error |
| 03 | Illegal Data Value | Register count or value out of range |
| 04 | Slave Device Failure | Internal device error |
| 06 | Slave Device Busy | The device is busy with another operation |
| 0A | Gateway Path Unavailable | No routing defined for the Unit ID |
| 0B | Gateway Target Failed to Respond | The serial device did not respond: address, cable, speed, parity |
Receiving no response at all (a timeout on the TCP side) and a 0B exception are different things: the first points to the client–gateway path or the gateway mode, the second to the serial side. The order of checks follows from this. For a quick test, the open-source mbpoll tool can be used; send queries only to devices you are authorised for and with the plant’s approval:
# Read 10 holding registers from Unit ID 5 via the gateway (single query)
mbpoll -m tcp -a 5 -r 1 -c 10 -t 4 -1 192.168.10.50
# Read the same device directly from the serial line (9600, even parity)
mbpoll -m rtu -a 5 -b 9600 -P even -r 1 -c 10 -t 4 -1 /dev/ttyUSB0
If both commands return the same values, the device and addressing are correct; the problem lies in the gateway configuration or the client. If the serial read also fails, leave the gateway and go back to the cable and the device settings. In Wireshark, the filter mbtcp shows Modbus TCP traffic, and mbtcp.unit_id == 5 shows requests to a specific device.
Migration checklist
- The device list, addresses, speed, parity and stop bit settings of each RS-485 line are documented; there are no address conflicts.
- Line termination and biasing are verified; the line topology is not a star.
- The gateway mode is set to “Modbus TCP ↔ RTU conversion”.
- A Unit ID–port mapping table has been prepared; Unit ID 0 is not used for reads.
- The line round time has been calculated with an example calculation; poll times are above it.
- Serial and TCP timeouts are set in layers.
- The gateway is the only master on the serial line; old masters have been removed.
- The clients that will connect to the gateway and the number of connections are defined.
- Address offset has been checked with a known register value.
- The gateway’s management interface is on the OT management network; Modbus TCP 502 access is restricted to authorised clients only.
If transferring Modbus data to higher-level systems is the next step, the article methods for reading data from Siemens S7 PLCs compares different reading approaches. To restrict Modbus TCP access at protocol level on the firewall, see the article Modbus and S7 deep packet inspection rules; Modbus itself has no authentication. For gateway selection and protocol conversion projects, see our edge gateways and protocol conversion page, and for integration on the PLC side, our PLC-to-PLC and PLC-to-server integration page.
Frequently asked questions
What value should the Unit ID be set to in Modbus TCP?
For serial devices behind a gateway, the Unit ID must equal the device’s slave address on the RS-485 line. For devices connected directly to Ethernet, 255 or the value stated in the device documentation is usually used; 0 is the broadcast address on a serial line.
I can connect to the gateway but keep getting timeouts; what should I check first?
The first thing to check is the gateway mode: it must be set to convert between Modbus TCP and RTU. Then check the serial speed, parity and slave address, and that the client timeout is longer than the gateway timeout.
What does exception 0B mean?
0B shows that the gateway forwarded the request onto the serial line but received no response from the target device. The problem is on the serial side: a wrong address, a cable or termination fault, or a speed or parity mismatch are the most common causes.
Can more than one SCADA connect to the same gateway?
They can, but all requests share the same serial line, and the gateway has a limit on simultaneous connections. Calculate the line capacity; if possible, have a single data collector read the serial line and let other systems get the data from it.