What is Modbus?

Modbus is a communications protocol that lets controllers and instruments exchange readings, status and settings over a serial connection or an IP network.

To read a value, a logger sends a function code and a register address. The device’s register map gives the address, format and units of each value. Modbus Application Protocol Specification V1.1b3, §§4.1 and 4.3–4.4

A gateway connects a controller over Ethernet to a device on a two-wire RS-485 line.

Why it was developed

Modicon introduced Modbus in 1979 so its industrial controllers and other control equipment could exchange process data. A common set of commands let one device ask another to read or write values such as input states and counter totals. Modbus Organization’s introduction

Modbus TCP later carried the same command model over TCP/IP. The protocol defines how to read a register. The device’s register map tells you what the value represents and which units and scale to use. Modbus application protocol and TCP/IP guide

Follow one request for total operating time

The logger acts as the client and the device as the server. The client starts the exchange with a function code that identifies the operation. For a register read, the request includes the starting address and the number of registers to read. A normal response returns their contents. Modbus Application Protocol Specification V1.1b3, §§4.1 and 6.3–6.4

The protocol defines four data types. Discrete inputs are read-only bits, and coils are bits that can be read or written. Input registers are read-only 16-bit words. Holding registers are 16-bit words that can be read or written where the device allows it. The device’s register map identifies the type, address and permitted operations for each reading or setting. Modbus Application Protocol Specification V1.1b3, §§4.3–4.4 and 6.6

Suppose the manual numbers holding registers from one and says the device stores total operating time in 101 and 102. Modbus addresses start at zero, so the logger subtracts one from 101 and sends starting address 100. It uses function 03 and asks for two registers. A successful response contains four data bytes, two per register. Some manuals already give the zero-based address, so check the numbering in the register map before converting it. Modbus Application Protocol Specification V1.1b3, §§4.4, 6.3 and 7

Modbus RTU, RS-485 and Modbus TCP

Modbus RTU frames Modbus messages for a serial line. RS-485 defines electrical signalling and is a common serial interface for RTU. An RTU frame carries the device address and a cyclic redundancy check (CRC) that helps detect transmission errors. On a shared RS-485 segment, the devices use matching serial settings, and the client polls one transaction at a time. In the example, a serial logger sends function 03, address 100 and quantity two directly to the RTU device. Serial Line Guide V1.02, §§2.1, 2.5 and 3.3

Modbus TCP sends the same read request over TCP/IP. The logger can send function 03, address 100 and quantity two directly to a TCP device. The logger uses the transaction identifier in the Modbus header to match the reply to its request.

If the device uses RTU, the logger sends that TCP request to a gateway. The gateway uses the unit identifier to select the device on the serial line, sends the read as an RTU request, then returns the two words in a TCP reply. The gateway changes the framing. The logger uses the same register map to decode the result. TCP/IP Messaging Guide V1.0b, §3.1.3 · §4.4.1.2

A TCP client sends function 03 with starting address 100 and quantity two. The gateway forwards the request over RS-485 as Modbus RTU and returns the two words to the client over TCP.

Download the diagram as a PNG

How the receiver finds the end of a message

On an RTU line, a silent interval separates one frame from the next. At 9,600 baud the minimum gap is 3.5 character times. With one start bit, eight data bits, one parity bit and one stop bit, that is about 4.0 ms. The exchange in this example uses an eight-byte RTU request and a nine-byte normal response, including the unit address and CRC in each frame. At those serial settings the bytes alone take about 19.5 ms to transmit in total. A polling budget also needs the time from the end of the request to the start of the response, which includes the required silent gap, plus the time before the next request. Modbus Serial Line Guide V1.02, §§2.5.1 and 2.5.1.1

Polling 20 devices with that same request and response takes about 390 ms for the bytes alone at 9,600 baud. If one device fails to reply, the logger may also wait for a timeout before it can poll the next device. Measure the complete scan with a device offline as well as with every device responding.

Modbus TCP uses the length field in the Modbus Application Protocol (MBAP) header to find the end of a message in the TCP byte stream. One request can arrive in several TCP segments. The length tells the receiver how many bytes follow, including the Unit Identifier and the function and data bytes. The five-byte request below has an MBAP length of 6. Count one byte for the Unit Identifier and five for the request PDU. Modbus TCP/IP Messaging Implementation Guide V1.0b, §§3.1.2–3.1.3

Why a successful read can give the wrong number

The device returns 0x0001 from register 101 and 0x0002 from register 102. In this example the map specifies an unsigned 32-bit total, with the high word first and a scale of 0.01 hours per count. The high word contributes 1 × 65,536 counts and the low word adds 2. That gives 65,538 counts, or 655.38 h. Swapping the words gives 1,310.73 h from the same reply.

The table shows only the Modbus protocol data unit (PDU), in hexadecimal. RTU and TCP wrap these same function and data bytes differently. Modbus Application Protocol Specification V1.1b3, §6.3

Message

PDU bytes

What the bytes mean

Read request

03 00 64 00 02

Function 03, starting address 100, quantity two

Normal reply

03 04 00 01 00 02

Function 03, four data bytes, register words 1 and 2

Exception reply

83 02

Exception form of function 03, illegal data address

Modbus defines byte order inside each 16-bit register and uses a zero-based address in the request. Check whether the manufacturer’s map gives that wire address directly or numbers the registers starting at one. Use the same map to check the data type, word order across registers, scale and unit. Modbus Application Protocol Specification V1.1b3, §§4.2–4.4 and 6.3

How recent is the displayed reading?

A Modbus exception is a reply that identifies a problem. For an unavailable address range, the device can return 0x83 for the failed function 03 and exception code 02. A timeout means the logger had no usable reply by its deadline. On a gateway connection, allow time for the serial exchange as well as the TCP leg. A deadline set too short can trigger unnecessary retries. Modbus Application Protocol Specification V1.1b3, §7 · TCP/IP Messaging Guide V1.0b, §4.4.1.4

Suppose the logger reads 655.38 h at 09:00. If the 09:01 poll returns an exception or times out, the dashboard may still show 655.38 h from 09:00. If the 09:01 poll succeeds and returns the same value, the register value is unchanged and the last successful read advances to 09:01. Check both the poll result and the last successful read time. Use the device’s measurement timestamp as well if it supplies one.

Where Modbus is used

What affects power consumption

Include the device, client, gateway and any separately powered network equipment when estimating power draw. An always-on gateway draws power between requests. Polling less often reduces the work spent on exchanges, and a device that can enter a lower-power state between polls may save more.

Illustrative daily budget. Suppose a device draws 0.6 W between polls, a logger acting as the client draws 0.9 W, and a gateway draws 1.5 W. All three stay on, so they use 3 W × 24 hours = 72 Wh per day before any polling activity. Assume each successful poll adds 1 W across the system for one second above that baseline.

Poll interval

Polls per day

Extra energy for polls

Total energy per day

10 seconds

8,640

2.4 Wh

74.4 Wh

60 seconds

1,440

0.4 Wh

72.4 Wh

Each poll adds one watt-second. Divide the daily total in watt-seconds by 3,600 to get watt-hours. The longer interval saves 2 Wh per day in this example because the continuously powered equipment still uses 72 Wh. These figures are assumptions for the example. They exclude network equipment, power conversion losses, retries and sensor warm-up.

For an actual installation, measure or estimate the power and time spent in each state over a representative polling cycle. Include retries and the draw of any powered equipment upstream of the gateway. Check peak current separately when sizing the power supply.

Pros and cons

Pros

Cons

Serial Line Guide V1.02, §2.1 · TCP/IP Messaging Guide V1.0b, §3.1.1 and §4.4.1.2

Back to the technology glossary