The same command (function code + address + quantity), when sent over Ethernet, puts on a different envelope—Modbus TCP. A TCP frame is like a courier package: a waybill with 7 pieces of information is attached at the front (the MBAP header), it states the "length" so the stream can be split precisely, and no stamp (CRC) is needed, because the TCP/IP stack already guarantees data integrity.
Modern factories, SCADA systems, and cloud platforms almost all use TCP. It supports multiple concurrent clients, crosses network segments, and feeds directly into databases and the web. Understand the MBAP header and gateways and you can seamlessly connect "serial devices in the workshop" to "systems in the office".
Transaction ID: the client numbers this request and the response carries the same number back, which is how questions and answers are paired on concurrent connections; Protocol ID: fixed at 0x0000 for Modbus; Length: how many bytes follow (unit ID + PDU), not counting itself; Unit ID: carries the RTU slave address when a gateway bridges a serial line; for a pure TCP slave it is usually 1 or 255.
Command: "read 2 holding registers from slave 5, starting at 0x0000" (TCP 12 bytes = MBAP header + PDU, transaction ID = 1):
00 01
00 00
00 06
05
03
00 00 00 02
| Byte | Value | Meaning |
|---|---|---|
| 0–1 | 00 01 | Transaction ID |
| 2–3 | 00 00 | Protocol ID |
| 4–5 | 00 06 | Length (unit ID + PDU) |
| 6 | 05 | Unit ID |
| 7 | 03 | Function code |
| 8–9 | 00 00 | Starting address |
| 10–11 | 00 02 | Quantity |
Length = 0x0006 = 6 bytes follow (1 byte unit ID + 5 bytes PDU). TCP has no CRC—data integrity is the responsibility of the TCP/IP stack. Compared with Chapter 6, the same content takes 8 bytes in RTU (2 extra CRC bytes, but 7 fewer MBAP bytes).
| Aspect | RTU | TCP |
|---|---|---|
| Header | 1 byte (address) | 7 bytes (MBAP) |
| Trailer | 2-byte CRC-16 | None |
| Overhead per frame | 3 bytes | 7 bytes |
| Frame boundary | ≥3.5 characters of silence | Length field |
| Transaction matching | Implicit (one question at a time) | Explicit (transaction ID) |
| Multiple masters | Not supported | Multiple clients supported |
What Ms. Wang's gateway does: receive a TCP request → strip off the MBAP header → take out the PDU → convert it into an RTU frame for the slave indicated by the unit ID → receive the response → wrap it in a new MBAP header → return it to the TCP client. As far as the office app is concerned, it only ever speaks TCP; as far as the sensors in the greenhouse are concerned, it only ever speaks RTU—the gateway is the translator between the two.
00 01 00 00 00 06 05 03 00 00 00 02 (the transaction ID may differ);In this chapter you learned about the TCP "courier waybill": a 7-byte MBAP header (transaction ID / protocol ID / length / unit ID) + PDU, framed by the length field, paired by the transaction ID, and with no CRC. You also saw clearly how an RTU↔TCP gateway acts as a translator.
That wraps up the theory. In the next chapter, the doors of the Lab open—go and assemble this chapter's frames by hand, and see whether your fingers agree with the protocol specification.