



You can use your RevPi as a Modbus server (master) or as a Modbus client (slave). For these types of transmission, corresponding virtual devices are available as interfaces via PiCtory. A maximum of 32 registers can be used per virtual device for input and output data. Up to 30 Modbus virtual devices can be configured for additional inputs and outputs.
-
ModbusTCP Slave
-
ModbusTCP Slave (512 I/O words)
-
ModbusRTU Slave
-
ModbusRTU Slave (512 I/O words)
-
ModbusTCP Master
-
ModbusTCP Master (150 input words)
-
ModbusRTU Master
-
ModbusRTU Master (150 input words)
Compared to other fieldbuses, Modbus is a simple alternative for exchanging data. The Modbus protocol is open. It is based on server-client communication. In principle, every participant in the network can send data. In practice, however, communication is always initiated by the server.
Transmission Types (selection) #
-
Modbus RTU (Remote Terminal Unit):
-
Serial communication
-
Data is transmitted in binary form
-
-
Modbus TCP (Transmission Control Protocol)
-
Extended Modbus RTU for TCP/IP networks
-
Modbus Server #
-
Requests data from Modbus clients
-
Acts as a client, as it does not provide any data
Modbus Client #
-
Provides data
-
Acts as a server because it provides data
Modbus Register #
A Modbus register is a 16-bit memory location (2 bytes) used for data storage and transmission in the Modbus protocol. Registers can store values from 0 to 65,535 (unsigned).
The registers available are device-specific. The registers are counted either from 0 or from 1.
Register Types in the Modbus Data Model #
Modbus defines four memory areas with different access rights.
Holding Registers (40001 … 49999) #
-
Readable and writable
-
Storage of setpoints, configuration data
-
Function code 03 (read), 06/16 (write)
Input Registers (30001 … 39999) #
-
Read-only
-
For measured values, sensor data
-
Function code 04 (read)
Coils (00001 … 09999) #
-
Individual bits, readable and writable
-
Digital outputs (on/off states)
Discrete Inputs (10001 … 19999) #
-
Individual bits, read-only
-
Digital inputs
Addressing #
Register addressing varies depending on the context:
-
Protocol level: 0-based (0 … 65535)
-
User level: 1-based with prefix (e.g., 40001 for first holding register)
Example:
Holding register 40001 is transferred to the protocol level as address 0.
Data Interpretation #
Since a register only stores 16 bits, larger data types are distributed across several registers:
-
32-bit float: 2 consecutive registers
-
64-bit double: 4 consecutive registers
-
Strings: One character per register or packed (2 characters/register)
Byte Order #
The interpretation of bytes within a register and across multiple registers can vary:
-
Big-endian: Higher-order byte first (Modbus standard)
-
Little-endian: Low-order byte first
-
For multi-register values, additionally: Observe word order
Example:
-
Temperature value: 23.5 °C
-
Scaling: Value × 10 stored
-
Register content: 235 (0x00EB)
-
Transmission: [0x00][0xEB]
Functions or Services #
-
Implement access to data
-
Distinction
-
Read
-
Write
-
Both
-
-
Data width
-
Data word (2 bytes)
-
Bit
-
-
Which functions are implemented depends on the device
Query Data #
▷ Configure the data connection between the Modbus server and Modbus client.
-
Modbus TCP – Network configuration (static IP addresses, netmask)
-
Modbus RTU – Serial interface (baud rate, data bits, parity, stop bits)
▷ Call up the corresponding function provided by the client on the Modbus server.
Modbus RTU Client ID #
In Modbus RTU, the client ID is mandatory and has the following functions:
-
Unique addressing of each device on the bus in the value range 1 … 247.
-
Enables the master to address individual slaves.
-
Each device on the same bus must have a unique client ID.
-
ID 0 is reserved for broadcast messages.
Modbus TCP Unit ID #
The unit ID is used either for direct device identification or for gateway addressing:
-
Either the unit ID identifies a specific Modbus TCP device that is addressed directly via its IP address. In this case, the unit ID corresponds functionally to the client ID.
-
Or the unit ID addresses devices behind a Modbus TCP to RTU gateway. The following applies: Unit IDs 1-247 address the Modbus RTU devices behind them, while unit ID 255 addresses the gateway itself.
The correct setting depends on the device type: For direct Modbus TCP devices, the device-specific unit ID is used; for gateway configurations, either the unit ID of the target device (1 … 247) or 255 for the gateway itself is used.
Modbus Function Codes (examples) #
Code |
Function |
0x01 |
Read coils |
0x02 |
Read discrete inputs |
0x03 |
Read holding registers |
0x04 |
Read Input Registers |
0x05 |
Write Single Coil |
0x06 |
Write Single Register |
Example of information required for Modbus RTU:
-
Serial interface parameters: 9600 baud, 8 data bits, 1 stop bit, no parity
-
Client address: 1
-
Modbus register: 1000
-
Modbus function: READ_INPUT_REGISTER
Example of information required for Modbus TCP:
-
IP address of the client: 192.168.0.103
-
Unit ID: 255
-
Client register: 1000
-
Modbus function: READ_HOLDING_REGISTER