Note: This is a sample technical write-up showcasing article structure, math formulas, and code syntax highlighting.
When commissioning field instruments or PLC communication links over Modbus RTU (RS-485) or Modbus TCP, communication failures usually stem from a handful of deterministic issues.
1. The 0-Based vs 1-Based Register Addressing Trap
Modbus specifications define register addresses starting at 0, but vendor documentation often refers to 5-digit or 6-digit schema starting at 40001 or 30001.
- If reading holding register
40001returns anIllegal Data Address (Exception 0x02), subtract 1 and poll address0x0000. - In PLC ladder logic and Node-RED
node-red-contrib-modbus, verify whether the node expects the zero-offset address or the standard offset.
| Modbus Entity | Typical Documentation | Protocol Hex Address | Function Code |
|---|---|---|---|
| Discrete Output (Coil) | 00001 - 09999 | 0x0000 | 0x01 (Read), 0x05 (Write) |
| Discrete Input (Contact) | 10001 - 19999 | 0x0000 | 0x02 (Read) |
| Input Register (Read-Only) | 30001 - 39999 | 0x0000 | 0x04 (Read) |
| Holding Register (R/W) | 40001 - 49999 | 0x0000 | 0x03 (Read), 0x06 / 0x10 (Write) |
2. Word and Byte Endianness in 32-Bit Telemetry
Standard Modbus registers are 16 bits wide. When reading 32-bit floating-point numbers (IEEE 754) or 32-bit integers, two adjacent registers must be concatenated.
There are four common combinations:
- Big-Endian (AB CD): High byte first, high word first.
- Little-Endian (CD AB): Low word first, low byte first.
- Mid-Big / Word-Swapped (CD AB): Low word first, high byte first.
- Mid-Little / Byte-Swapped (BA DC): High word first, low byte first.
Python Verification Script
You can verify register decoding using pymodbus or standard struct:
import struct
# Simulated raw registers returned from PLC: [0x42f6, 0xe979]
reg_high = 0x42f6
reg_low = 0xe979
# Pack registers as 16-bit unsigned ints, then unpack as 32-bit float
raw_bytes = struct.pack('>HH', reg_high, reg_low)
float_val = struct.unpack('>f', raw_bytes)[0]
print(f"Decoded Process Variable: {float_val:.2f}")
3. Engineering Math: Calculating Baud Rate Transmission Time
On RS-485 serial links, calculating query latency is critical for setting polling intervals without causing bus collisions.
The transmission time for an -byte frame at baud rate with 1 start bit, 8 data bits, 1 stop bit, and parity (11 bits per character) is modeled by:
Where is the mandatory inter-frame silent interval:
For a standard 8-byte poll request at :
If your polling cycle is set faster than the combined turnaround time of all multidrop slaves, buffer overflows and CRC timeouts are inevitable.