What is the Modbus protocol?
Part of the Modbus guide
The Modbus protocol is an application-layer messaging protocol in which a client sends a request to a server and the server replies with data or an error. Every request names a function code (read holding registers, write a coil) and an address range, and every value lives in one of four tables of bits or 16-bit registers. The same messages run over RS-485 serial lines as Modbus RTU and over Ethernet as Modbus TCP.
This page is part of the Modbus guide. It covers the parts of the protocol that are the same on every transport.
How does the Modbus protocol work?
A Modbus exchange has two roles. The client starts every transaction; the server only answers. On a serial line the specification calls them master and slave, and most device manuals still do. A PLC, an HMI or a data collector is normally the client. Drives, meters, sensors and controllers that expose data are servers. A server never speaks first, so there is no way for a device to report a change on its own: the client has to poll.
The unit that both sides exchange is the protocol data unit, or PDU. It is one function code byte followed by data, and it is limited to 253 bytes.
| Part | Size | Content |
|---|---|---|
| Function code | 1 byte | What to do, 0x01 to 0x7F |
| Data | 0 to 252 bytes | Addresses, quantities and values, depending on the function |
Each transport wraps the PDU in its own envelope to form an application data unit (ADU). The serial envelope adds a one-byte device address in front and an error check behind. The TCP envelope adds a seven-byte header in front. The PDU inside is byte for byte the same, which is why a gateway can move a request from Ethernet to RS-485 without understanding it.
A server that cannot carry out a request returns an exception response: the function code with its top bit set (so 0x03 becomes 0x83) and a one-byte exception code. The function code reference lists the codes and what each means.
The four data tables
The Modbus protocol defines four kinds of data. Two are single bits and two are 16-bit words; in each pair, one is read-only and one is read-write.
| Table | Size | Access | Read with | Write with | Traditional numbering |
|---|---|---|---|---|---|
| Coils | 1 bit | Read and write | 0x01 | 0x05, 0x0F | 0xxxx |
| Discrete inputs | 1 bit | Read only | 0x02 | none | 1xxxx |
| Input registers | 16 bits | Read only | 0x04 | none | 3xxxx |
| Holding registers | 16 bits | Read and write | 0x03 | 0x06, 0x10 | 4xxxx |
Each table has its own address space of 65,536 items. The specification leaves it to the device vendor to decide what goes where and whether the tables overlap in memory. In practice many devices put everything, including read-only measurements, in holding registers.
Register addresses and the off-by-one trap
This is the most common source of wrong readings, and it comes from two numbering schemes that differ by one.
On the wire, a request carries a 16-bit address from 0 to 65535. In the data model, the specification numbers the items of each table from 1. Item number 1 is at address 0. So the first holding register is register 1 and is read with address 0x0000.
Device manuals add a third layer: the Modicon convention of prefixing the register number with a digit that names the table. Holding register 1 is written 40001, input register 1 is 30001. The prefix is documentation shorthand. It is never sent; the function code already tells the server which table is meant. This convention is not part of the Modbus specification, and vendors apply it loosely.
| In the manual | Table | Register number | Address on the wire |
|---|---|---|---|
40001 | Holding registers | 1 | 0x0000 |
40108 | Holding registers | 108 | 0x006B |
30009 | Input registers | 9 | 0x0008 |
00173 | Coils | 173 | 0x00AC |
Three things go wrong here:
- The manual lists zero-based addresses but the polling software expects one-based register numbers, or the reverse. Every value appears to belong to its neighbour.
- The manual uses six digits (
400001) so that the full range fits.400001and40001are the same register. - The manual prints addresses in hexadecimal without saying so.
When a reading looks wrong, read one register above and one below the documented address before changing anything else. If a neighbour holds the expected value, the problem is the offset.
32-bit values: byte order and word order
A register is 16 bits. The specification says how to send it: high byte first. It says nothing about values wider than one register, so 32-bit integers, IEEE 754 floats and 64-bit values are a vendor decision. They are stored in consecutive registers, and the order of those registers varies.
Take the float 123.456, which is 0x42F6E979. A device stores it in two registers in one of four ways:
Order Register N Register N+1 Common name
ABCD 0x42F6 0xE979 big-endian, high word first
CDAB 0xE979 0x42F6 word swapped, low word first
BADC 0xF642 0x79E9 byte swapped
DCBA 0x79E9 0xF642 little-endianDecode the CDAB layout as if it were ABCD and 123.456 becomes roughly -1.9 × 10^25. That is the signature of a word order mismatch: values that are absurdly large, absurdly small, or jump wildly while the process is steady. A 32-bit integer that reads as a multiple of 65,536 points the same way.
Good register maps state the order. When they do not, find a value you can verify independently (a voltage, a setpoint you can see on the device display) and try ABCD and CDAB first; together they account for most devices.
Serial and Ethernet variants
The Modbus protocol has three framings in use:
- Modbus RTU sends the PDU as binary over a serial line, almost always RS-485, with a device address in front and a CRC-16 behind. One client, up to 247 addressable servers.
- Modbus ASCII sends each byte as two hexadecimal characters with a start colon and a longitudinal redundancy check. It is rare in new equipment.
- Modbus TCP sends the PDU over a TCP connection to port 502 behind a seven-byte header. Several clients can talk to one server at once.
The comparison of RTU and TCP covers how to choose and how gateways join the two.
What the protocol leaves out
Knowing the gaps saves time during design:
- No security. There is no authentication and no encryption in the base protocol. Any client that can reach a server can write to it.
- No discovery. A client cannot ask a server what registers it has. You need the vendor’s register map.
- No data types beyond bits and 16-bit words. Scaling, signedness, units and multi-register layouts all come from the manual.
- No timestamps and no report by exception. The client polls, and the time of a value is the time it was read.
Reading Modbus with ControlCom
ControlCom Connect is the hosted platform; the ControlCom Edge Server is the component on site that polls Modbus devices. Its Modbus client handles the two problems above directly. A Zero Based switch on the connection sets whether register numbers start at 0 or 1, and each tag takes an address that is the offset within its table rather than the prefixed number: for a holding register documented as 400001, the address is 1. Each unit has a bigEndian toggle for byte order and a swapWords toggle that reverses the register order for 32-bit and larger types, and a single tag can override both.
The Modbus client documentation walks through the fields, and the platform overview follows a value from the device to a dashboard. For the commissioning workflow, see the page for controls engineers.
Map a register to a variable once on the Edge Server, with its data type, word order and scaling, and ControlCom Connect stores, trends and alarms on it from then on.