Modbus — Industrial Communication Protocol
Definition and History
Modbus is an industrial communication protocol released in 1979 by Modicon (now Schneider Electric) to enable communication between its programmable logic controller and field devices. Having become an open, royalty-free standard in 2002, Modbus is now the most widely used protocol in the industry, found on hundreds of millions of devices worldwide.
Its popularity is based on three fundamental qualities: simplicity (easy to implement, well-documented), robustness (works over poor-quality connections), and interoperability (an open standard supported by virtually all industrial equipment—PLCs, variable-speed drives, energy meters, sensors, and controllers).
Despite its age, Modbus remains indispensable, particularly in existing (brownfield) installations and for low-cost equipment. Its main drawback is the lack of native security (no authentication, no encryption), which requires it to be protected behind a VPN when it travels over an uncontrolled network.
Modbus RTU vs. Modbus TCP
There are two main variants of the Modbus protocol:
Modbus RTU (Serial)
- Physical layer: RS-232 (point-to-point) or RS-485 (multi-drop bus supporting up to 32 devices, maximum distance of 1,200 m at 9,600 baud).
- Transmission: binary, compact. Each message contains the slave address, the function code, the data, and a CRC-16 integrity check.
- Topology: master-slave (a single master, up to 247 slaves addressable from 1 to 247).
- Applications: energy meters, variable frequency drives, industrial sensors with RS-485 output, legacy PLCs.
Modbus TCP (Ethernet)
- Physical layer: Ethernet (10/100/1000 Mbps), IP protocol, TCP port 502.
- Encapsulation: The Modbus RTU frame is encapsulated in a 7-byte MBAP (Modbus Application Protocol) header that replaces the CRC (Ethernet ensures integrity on its own).
- Topology: client-server (the client, formerly the master, queries the server, formerly the slave). Multiple clients can query the same server simultaneously.
- Usage: PLCs with Ethernet ports (Siemens S7, Schneider M340/M580, Allen-Bradley), HMIs/SCADA systems, cloud gateways.
| Criterion | Modbus RTU | Modbus TCP |
|---|---|---|
| Physical layer | RS-232 / RS-485 | Ethernet / TCP-IP |
| Typical Speed | 9,600 to 115,200 baud | 10/100 Mbps |
| Distance | Up to 1,200 m (RS-485) | Standard Ethernet network |
| Number of slaves | 1 to 247 | Unlimited (IP addressing) |
| Integrity check | CRC-16 | TCP checksum |
| Native security | None | None (use VPN) |
Structure of a Modbus Message
Modbus RTU — Frame
| Slave address (1 byte) | Function code (1 byte) | Data (N bytes) | CRC-16 (2 bytes) |
Example of an FC03 request that reads 2 registers starting at address 0x0000 on slave 1:
01 03 00 00 00 02 C4 0B
Modbus TCP — Frame (with MBAP header)
| Transaction ID (2 bytes) | Protocol ID (2 bytes, = 0x0000) | Length (2 bytes) | Unit ID (1 byte) | Function code | Data |
Modbus Registers
Modbus organizes data into four types of registers, identified by their reference address:
| Type | Address | Access | Description |
|---|---|---|---|
| Coils | 0x0001–0xFFFF (base 1) | Read/Write | Digital on/off outputs (bit) — status of a valve or relay |
| Discrete Inputs | 0x1001–0xFFFF | Read-only | Digital on/off (bit) inputs — status of an on/off sensor |
| Holding Registers | 0x4001–0xFFFF | Read/Write | 16-bit read/write registers — setpoints, parameters, measured values |
| Input Registers | 0x3001–0xFFFF | Read-only | 16-bit read-only registers — sensor measurements, process values |
Note: Actual addressing in frames starts at 0 (an offset of -1 relative to the documented references). Thus, the Holding Register referenced as 40001 is addressed as 0x0000 in the frame.
Common Function Codes
| Code | Hex | Name | Description |
|---|---|---|---|
| FC01 | 0x01 | Read Coils | Read the status of N coils (digital outputs) |
| FC02 | 0x02 | Read Discrete Inputs | Read the status of N digital inputs |
| FC03 | 0x03 | Read Holding Registers | Read the status of N 16-bit read/write registers — most commonly used |
| FC04 | 0x04 | Read Input Registers | Read the status of N 16-bit read-only registers |
| FC05 | 0x05 | Write Single Coil | Write a single digital output (0x0000 = OFF, 0xFF00 = ON) |
| FC06 | 0x06 | Write Single Register | Write a single 16-bit holding register |
| FC16 | 0x10 | Write Multiple Registers | Write multiple consecutive registers in a single transaction |
FC03 is by far the most commonly used code for monitoring: it allows you to read measurements, statuses, and counters for a piece of equipment.
Slave Addressing (Unit ID)
In Modbus RTU, each device on the RS-485 bus has a unique address ranging from 1 to 247. Address 0 is reserved for broadcasts—only write commands can be broadcast.
In Modbus TCP, the Unit ID field (formerly known as Slave ID) is included in the MBAP header. It is typically set to 1 or 255 for PLCs with a single device, but can be used to address different RS-485 buses behind the same Modbus TCP/RTU gateway.
Modbus Configuration on the Eziwan Gateway
The Eziwan Gateway natively supports Modbus RTU (via RS-485) and Modbus TCP (via Ethernet). Configuration is performed through the gateway's web interface:
- Select the protocol: Choose "Modbus RTU" or "Modbus TCP" from the Data Source menu.
- Serial Settings (RTU only): baud rate (9,600, 19,200, 38,400, 57,600, or 115,200), parity (None/Even/Odd), stop bits (1 or 2).
- Slave address: Enter the device address (1 to 247).
- Define data points: For each value to be read, specify the function code (FC01 to FC04), the register address, and the data type (INT16, UINT16, INT32, FLOAT32, BOOL).
- Acquisition interval: polling frequency (from 1 second to several minutes, as needed).
- Test the connection: use the "Read Test" function to verify that data is being read correctly before enabling cloud data upload.
Related Resources
- Complete Guide to RS-485 and Modbus
- Connecting a PLC to the Eziwan Platform
- Blog Post: Modbus TCP vs. RTU — When to Use Which?
- PLC / API — Programmable Logic Controller
Frequently Asked Questions
What is the difference between Modbus RTU and Modbus TCP?
Modbus RTU operates over an RS-485 serial link (multi-slave bus, up to 1,200 m); Modbus TCP encapsulates the same requests in an Ethernet/IP frame on port 502. A gateway bridges the two systems.
What is a Modbus register?
A 16-bit memory location identified by an address. The holding registers (FC03/FC06/FC16) store process values; 32-bit values (floating-point numbers, counters) occupy two consecutive registers.
Is Modbus secure?
No: The protocol does not use authentication or encryption. It must never be exposed to the Internet—the rule is to confine it to the local network and transport data to the cloud through an encrypted VPN tunnel.
How many devices can be connected to a Modbus RTU bus?
Up to 32 slaves without a repeater (247 possible logical addresses). Beyond that, or to mix different polling rates, the system is segmented into multiple buses on separate RS-485 ports.
Related Resources
- Modbus to the Cloud — Collect data from and monitor your Modbus devices
- Modbus RTU/TCP Gateway — the serial-to-IP bridge
- Modbus RTU vs. TCP — a detailed comparison
- Complete Modbus Guide — configuration and troubleshooting
- Industrial Protocols — the hub for OT protocols