Modbus: a working guide to RTU, TCP and function codes

Catalin NegruPublished 3 min read

Modbus is a request and response protocol for reading and writing values in industrial devices. A client asks a server for a block of coils or registers, the server answers with the data or an exception code, and nothing else happens on the link. Modicon published it in 1979 for its PLCs, the specification is now maintained by the Modbus Organization and is free to implement, and that combination of age and openness is why most PLCs, drives, power meters and generator controllers sold today still speak it.

This guide covers what the bytes on the wire mean, which settings have to match, and which mistakes produce which symptoms. The figures come from the Modbus Application Protocol Specification V1.1b3 and the Modbus Organization’s serial line and TCP/IP implementation guides.

Where Modbus is found

In a plant, Modbus is the common language between equipment from different vendors. A PLC polls variable frequency drives for speed and current, a power meter exposes kWh and demand in a block of registers, and a generator controller publishes engine hours and alarm bits. In buildings it sits next to BACnet, usually on meters, drives and packaged equipment. In water and wastewater it is often the interface a pump station PLC offers to anything outside the panel.

Two transports carry nearly all of this traffic: RS-485 serial lines daisy-chained from device to device, and Ethernet on TCP port 502. The function codes and the data they carry are identical on both.

How the pages in this guide fit together

What is the Modbus protocol? explains the client and server roles, the four data tables, how a register number in a manual such as 40108 turns into the address 0x006B on the wire, and how 32-bit values are split across two registers.

Modbus RTU covers the serial variant: a request and response decoded byte by byte, the CRC-16 calculation, the 3.5 character silent interval between frames, and RS-485 termination and biasing.

Modbus TCP covers the Ethernet variant: the seven-byte MBAP header, a decoded frame, what the unit identifier is for, and how connections and timeouts behave.

Modbus RTU vs TCP puts the two side by side, shows how one frame converts to the other, and explains what a serial-to-Ethernet gateway changes.

Modbus function codes is the reference page: every public function code, the quantity limits per request, and the exception codes a device returns when it refuses.

The problems that take the most time

Most Modbus faults fall into a short list, and each has a recognizable signature.

SymptomUsual causeCovered in
Every value is shifted by one registerRegister numbers start at 1, wire addresses start at 0What is the Modbus protocol?
A float reads as a huge or tiny numberWord or byte order of the 32-bit valueWhat is the Modbus protocol?
Timeouts on some devices of an RS-485 runTermination, biasing, polarity or duplicate addressesModbus RTU
Exception 02 on a register that existsWrong table, or a request that runs past the end of a blockModbus function codes
A gateway answers with exception 0BWrong unit identifier for the serial device behind itModbus TCP

Reading Modbus with ControlCom

ControlCom Connect is a hosted platform, so it does not poll field devices itself. The on-site component, the ControlCom Edge Server, does. It has a Modbus TCP client and a Modbus RTU client, each configured from the platform: the endpoint or serial port, the unit IDs behind it, and one tag per coil or register, mapped to a platform variable with a data type, scale and offset. The Edge Server applies a saved configuration on its next restart. The Modbus client documentation  lists every field, the platform overview shows where the values go next, and the page for controls engineers describes the commissioning workflow.

The Edge Server polls Modbus TCP and RTU devices on site and maps each register to a variable in ControlCom Connect, where it can be trended, alarmed on and reported.

In this guide

  1. 1What is the Modbus protocol?The Modbus protocol explained: client and server roles, the four data tables, register addressing and the off-by-one trap, and 32-bit byte and word order.
  2. 2Modbus RTU: frame format, timing, CRC and RS-485 wiringModbus RTU explained byte by byte: frame format, a decoded request and response with CRC-16, the 3.5 character silent interval and RS-485 wiring rules.
  3. 3Modbus TCP: the MBAP header, port 502 and the unit IDModbus TCP explained: the seven-byte MBAP header, a decoded request and response on port 502, what the unit ID does, and how connections and timeouts work.
  4. 4Modbus RTU vs TCP: differences, conversion and when to use eachModbus RTU vs TCP compared: framing, addressing, error checking, speed and wiring, how one frame converts to the other, and what a gateway changes.
  5. 5Modbus function codes: reference with examples and exception codesModbus function codes listed with request and response layouts, per-request quantity limits, worked examples, and the exception codes devices return.