The Mechanics of Communication

(Module 1 · Foundations – Understanding the Modbus Universe)


Learning Objectives

After completing this chapter you will be able to …

  1. Describe the canonical Modbus client–server architecture and its scheduling rules.
  2. Dissect any Modbus message into its two logical layers: PDU and ADU.
  3. Follow the entire request-→response transaction cycle in both serial (RTU/ASCII) and TCP networks, including framing gaps and timeouts.
  4. Apply correct addressing: slave IDs, broadcast ID 0, and the special Unit Identifier field used by gateways.

3.1 The Client-Server Model (a.k.a. Master-Slave)

3.1.1 Roles & Responsibilities

RoleObligationsCannot do
Client (Master)Initiates every query• Manages timing & retries• Aggregates data from ≥1 serversReceive unsolicited frames
Server (Slave)Waits silently• Executes request• Returns normal or exception responsePoll other devices

Tip Think of the client as a bus conductor: only it asks questions, validates tickets, and decides when to move on.

3.1.2 Medium Access Rules (Serial Bus)

  1. Only one client per RS-485 segment (strict).
  2. Up to 247 servers (addresses 1 – 247).
  3. Broadcast: address 0 — all servers act, none respond.
  4. Servers must wait a minimum 3.5 character times after the line becomes idle before treating the next byte as a new frame.

Pitfall Adding a second polling engine (e.g., a laptop with Modbus scanner) on the same serial trunk will corrupt traffic unless you implement arbitration outside the protocol.

3.1.3 Beyond One-Master Limits

  • Multi-master token buses (e.g., Modbus Plus) rotate a hardware token; Modbus/TCP simply relies on Ethernet CSMA/CD and TCP sockets.
  • Gateways can queue requests from multiple TCP clients and serialize them onto RS-485 while preserving timing gaps — but throughput collapses if you ignore inter-frame timing (see 3.3).

3.2 Message Anatomy — PDU vs ADU

Key idea: keep the Protocol-Data Unit (PDU) identical across all media; wrap it in a media-specific Application-Data Unit (ADU).

3.2.1 Protocol-Data Unit (PDU) — “What to do”

Byte(s)NamePurpose
1Function CodeVerb (read coils, write reg…)
NDataAddress, length, payload, etc.

Every PDU is stateless; it never contains the source-or-destination address.

3.2.2 Application-Data Unit (ADU) — “Who & how”

VariantADU Fields (in order)Error Check
RTUSlave Addr (1) · PDU · CRC-16 (2)CRC-16 (poly 0xA001)
ASCIIStart : · Slave Addr (2 ASCII) · PDU (ASCII) · LRC (2) · CR LFLRC (8-bit)
TCPMBAP Header (7) · PDUTCP checksum (in IP)

MBAP (Modbus-Application Protocol) Header

Byte(s)FieldDescription
0-1Transaction IDEchoed so client matches replies.
2-3Protocol ID = 0x0000Reserved for future multiplexing.
4-5LengthBytes to follow (Unit ID + PDU).
6Unit Identifier0–255; 255 = broadcast; used by gateway to route to serial slave.

(Diagram placeholder: three color-coded frame layouts stacked for RTU, ASCII, TCP.)


3.3 The Modbus Transaction Cycle

3.3.1 Serial (RTU/ASCII) Timing Diagram

(Sequence-chart placeholder with nanosecond scale for bytes, T1.5 gap, T3.5 inter-frame.)

  1. Client assembles frame → toggles TX-Enable, transmits.
  2. Bus idle ≥ T3.5 → servers know frame is complete.
  3. Designated server validates CRC/LRC.
  4. Server processing delay ( 5 – 10 ms typical PLC).
  5. Server replies; other servers ignore traffic.
  6. Client validates, copies data to tag-table, or handles exception.
  7. Timeout: if no frame within Timeout (e.g., 100 ms) → retry or flag alarm.

Tip The #1 field failure is ignoring T3.5 when bit-rate ≠ spec default. Calculate:

Tchar = 11 bits / Baud  
T3.5 = 3.5 × Tchar

3.3.2 TCP Transaction

Client TCP socket ----> Server TCP 502
 |--------------- PDU ---------------->|
 |<-------------- PDU/exception --------|

No timing gaps, but you must:

  • Keep one outstanding query per Transaction ID (avoid head-of-line blocking).
  • Design for Nagle + Delayed ACK interactions or disable Nagle if latency matters.

3.4 Addressing & Unit Management

ContextFieldRangeNotes
Serial RS-485Slave Address1-247248-255 reserved
Broadcast0Servers act, never respond
TCPUnit Identifier0-255Often = serial slave ID behind gateway
Gateway Fan-OutIP → many RS-485 bussesUnique (IP,UnitID) must map to unique physical slave

Tip When devices appear to “shift addresses” behind a gateway, double-check the gateway’s address offset or ID remap table.


3.5 Worked Example — Byte-Level Walkthrough

Scenario PLC client wants the first six holding registers from slave 17. Baud 19 200, 8-E-1.

FieldHexComment
Addr11Slave 17
Func03Read Holding Registers
Start-Hi0040001 (0-based) high byte
Start-Lo0040001 low byte
Qty-Hi006 regs
Qty-Lo06
CRC-LoC5Calculated CRC-16 little-endian
CRC-HiC4

Server’s normal response (12 bytes + CRC) returns Byte-count = 12, then 6× 16-bit values.

(Code snippet placeholder: Python pymodbus call client.read_holding_registers(0,6,unit=17) with decoded result.)


3.6 Exception Responses

If the slave cannot fulfil a request:

ByteMeaning
1Slave Addr
2Function Code + 0x80 (e.g., 0x83)
3Exception Code (02 = Illegal Data Address)
4-5CRC

Client must branch on fc & 0x80. Never ignore exceptions: mis-handling doubles network load via futile retries.


3.7 Key Takeaways

  1. One PDU, many wrappers — learn the 6-byte core once; the bus is “just plumbing.”
  2. Timing matters on serial links; bytes + silent gaps form the true frame.
  3. Transaction ID + Unit ID keep multi-client TCP and gateway scenarios sane.
  4. Exception frames are first-class citizens—handle them as deliberately as reads and writes.

Placeholder Assets to Create

IDVisualPurpose
Fig-3-1Client–server timeline (RTU)Show T1.5 / T3.5 gaps
Fig-3-2ADU vs PDU layer cakeReinforce separation
Fig-3-3MBAP header call-outsField-length cheat-sheet
Fig-3-4Gateway address fan-out mapClarify Unit ID use

Coming Up Next

In Module 2 we leave theory and put bytes on the wire, starting with Chapter 4: Serial Physical Layers — RS-485, RS-232 & RS-422. You’ll learn cabling rules, scope-probe tricks, and why bias resistors prevent “ghost frames.” Prepare your oscilloscope!

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

Chapter 9 – Modbus Gateways

— Bridging Serial & TCP/IP Worlds (Module 3 · Modbus TCP/IP) Ambition for this chapter: Build the best single source on earth for everything that happens inside a Modbus gateway—PCB…