SCADA, HMIs and PC programs often speak only Modbus TCP, while the devices (drives, temperature controllers, power meters) are RS-485 Modbus RTU. The usual answer is a gateway box, but for testing, commissioning or a small machine a PC with an RS-485 adapter can do the job. PortDock Serial's «Port sharing» mode «Modbus TCP ↔ RTU gateway» (from 0.10.0) does exactly that.
1. What the gateway does
A Modbus TCP request is a 7-byte MBAP header (transaction ID 2 · protocol ID 2 (always 0) · length 2 · Unit ID 1) followed by the PDU (function code + data). RTU is a 1-byte unit address + the same PDU + a 2-byte CRC. The gateway moves the Unit ID into the address byte, appends the CRC and sends it on the bus; from the reply it strips address and CRC and returns it with the same transaction ID.
| Bytes | Meaning |
|---|---|
| 00 01 00 00 00 06 03 03 00 00 00 02 | TCP request — transaction 1, length 6, Unit ID 3, FC03 two registers from 0 |
| 03 03 00 00 00 02 C5 E9 | RTU request on the bus — unit 3, same PDU, CRC E9C5 (low byte first) |
| 03 03 04 00 64 00 C8 99 BA | Device RTU reply — values 100, 200 |
| 00 01 00 00 00 07 03 03 04 00 64 00 C8 | TCP reply — transaction 1 unchanged, length 7 |
| 00 01 00 00 00 03 03 83 0B | No reply — exception 0B (gateway target failed to respond) |
2. Preparation
- Plug the RS-485 adapter (USB) into the PC and wire A, B and GND to the device bus. For wiring and termination see «RS-485 wiring checks».
- Make sure no two devices share an address and that all use the same baud rate and parity. The gateway uses one setting per bus.
- In PortDock Serial, «Connect» that COM port with the devices' baud rate and parity. Set receive framing to «Modbus RTU» so each reply is its own log line.
3. Turning it on
- Expand «Port sharing (TCP)» on the left and set «Mode» to «Modbus TCP ↔ RTU gateway». The TCP port changes to the Modbus TCP default, 502.
- Set «Response timeout» comfortably above the slowest device's reply time (default 1000 ms). Without a reply in time the client gets exception 0B.
- If you fill in «Units to forward» (e.g. 1-5, 10), other Unit IDs are not sent to the bus and get exception 0A (gateway path unavailable) at once — a missing address no longer holds the bus for a full timeout each time. Empty forwards all of 1–247.
- «Start sharing». In SCADA or the HMI enter server 127.0.0.1 (same PC) or this PC's IP, port 502, and Unit ID = the device address.
Windows lets you open ports below 1024 without administrator rights, so 502 works as is. If another Modbus server (a Modbus Slave simulator, for example) already has 502, starting tells you which program — pick another number. For SCADA on another PC, turn on «Allow other PCs to connect (0.0.0.0)» — Modbus has no authentication, so only on a network you trust.
4. One request at a time — why it can look slow
Two-wire RS-485 is half-duplex: only one frame can be on the bus at a time. So the gateway puts requests from all clients in one line, sends the next one only after the previous reply (or timeout), and keeps 3.5 characters (1.75 ms above 19200 bps) between frames. However fast the TCP side is, the serial speed sets the throughput.
- At 9600 bit/s, reading 10 holding registers is an 8-byte request + 25-byte reply = 33 characters, about 37.8 ms of transfer (33 × 11 ÷ 9600) plus device processing.
- When several clients poll the same bus, the line grows and each one sees longer response times. Set client timeouts above «gateway timeout × requests that can be waiting».
- If one device is off, every request to it holds the bus for the full timeout. Remove unused addresses from «Units to forward» or stop polling them.
5. Unit ID 0 and broadcast
In RTU, address 0 is broadcast — every device takes the write and nobody replies. By default the gateway does not pass Unit ID 0 on to RS-485 and answers with exception 0A (no route), so a stray request cannot write to every device on the bus. With «Unit ID 0» set to «Broadcast» (and, if you set an allowed-unit list, 0 included in it) the gateway sends to address 0, waits for no reply and sends none to the client (use it for write functions only). Some SCADA packages always send Unit ID 0; for those choose «Send to the default unit» and enter the device address.
6. Reading the log and statistics
- Sent lines in the traffic log are tagged like «TCP #1 → RTU unit 3 FC03» — which client, which request. The received line just below is its reply.
- GW event lines: «no response (1000 ms) → exception 0B», «unit ID 250 has no route → exception 0A», «dropped broken response (CRC error / cut short)».
- Statistics under the panel: requests, responses, device exceptions, timeouts, no route, broken replies, broadcasts and response time (last/avg/max). Rising broken replies point at wiring, termination and grounding; timeouts on one address only point at that device's address, baud rate or power.
- Exceptions from the device (01, 02, 03 …) go to the client unchanged — fix the request address or count. See «Modbus exception codes» for the meanings.
7. When to buy a gateway box
If the PC shuts down or sleeps, the gateway stops too. Around-the-clock machines, sites with no room for a PC, or several separate buses call for a dedicated gateway. A PC gateway is good for commissioning, testing, temporary links — and for checking SCADA settings and device replies before you buy the box.
Sources
- Modbus Messaging on TCP/IP Implementation Guide V1.0b — MBAP header, Unit ID, gateways
- MODBUS over Serial Line Specification and Implementation Guide V1.02 — 3.5-character gap, broadcast address 0, RS-485 half-duplex
- Modbus Application Protocol Specification V1.1b3 — §7 exception codes 0A and 0B
Published 2026-10-31