What Modbus TCP Is
Modbus TCP is Modbus transported over Ethernet TCP/IP. It uses the same function codes and data model as Modbus RTU but replaces serial framing and CRC with a TCP header (MBAP — Modbus Application Protocol header).
The default TCP port is 502.
MBAP Header
| Field | Size | Purpose |
|---|---|---|
| Transaction ID | 2 bytes | Matches requests to responses |
| Protocol ID | 2 bytes | Always 0x0000 for Modbus |
| Length | 2 bytes | Remaining message length |
| Unit ID | 1 byte | Device identifier (relevant for gateways) |
Unit ID
In Modbus TCP, the Unit ID field identifies the target device behind a gateway. For standalone Modbus TCP devices, Unit ID is typically 1 or 255. For gateways bridging TCP to serial, the Unit ID maps to the downstream RTU slave ID.
[!NOTE] Some Modbus TCP devices ignore the Unit ID entirely. Others require it to be a specific value. Always confirm with the vendor’s documentation.
TCP vs RTU
| Aspect | Modbus TCP | Modbus RTU |
|---|---|---|
| Error detection | TCP checksums (no CRC) | CRC-16 |
| Concurrent connections | Multiple | Single bus (one master polls) |
| Distance | Unlimited (IP network) | ~1200 m (RS-485) |
| Latency | Network dependent | Baud rate dependent |