Skip to main content
Kevin Nurmaulana WibowoAutomation & IoT
Protocols • 3 min read

A Field Engineer's Checklist: Troubleshooting Modbus TCP & RTU

Diagnosing register offset mismatches, parity errors, timeout exceptions, and word-order endianness in industrial field networks.

#Modbus#Industrial IoT#Troubleshooting

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 40001 returns an Illegal Data Address (Exception 0x02), subtract 1 and poll address 0x0000.
  • 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 EntityTypical DocumentationProtocol Hex AddressFunction Code
Discrete Output (Coil)00001 - 099990x00000x01 (Read), 0x05 (Write)
Discrete Input (Contact)10001 - 199990x00000x02 (Read)
Input Register (Read-Only)30001 - 399990x00000x04 (Read)
Holding Register (R/W)40001 - 499990x00000x03 (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:

  1. Big-Endian (AB CD): High byte first, high word first.
  2. Little-Endian (CD AB): Low word first, low byte first.
  3. Mid-Big / Word-Swapped (CD AB): Low word first, high byte first.
  4. 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 TframeT_{\text{frame}} for an NN-byte frame at baud rate BB with 1 start bit, 8 data bits, 1 stop bit, and parity (11 bits per character) is modeled by:

Tframe=11×NB+T3.5T_{\text{frame}} = \frac{11 \times N}{B} + T_{3.5}

Where T3.5T_{3.5} is the mandatory inter-frame silent interval:

T3.5=3.5×11B=38.5B secondsT_{3.5} = \frac{3.5 \times 11}{B} = \frac{38.5}{B}\text{ seconds}

For a standard 8-byte poll request at 9600 bps9600\text{ bps}:

Tpoll=11×89600+38.59600≈9.17 ms+4.01 ms=13.18 msT_{\text{poll}} = \frac{11 \times 8}{9600} + \frac{38.5}{9600} \approx 9.17\text{ ms} + 4.01\text{ ms} = 13.18\text{ ms}

If your polling cycle is set faster than the combined turnaround time of all multidrop slaves, buffer overflows and CRC timeouts are inevitable.