First published in February 2022, updated in April 2023
What is Modbus?
Modbus is a client/server (formerly master/slave) based communication protocol that has become the de facto standard in the industry. One reason for this is that it is an open protocol.
By means of Modbus, a client (e.g. a myDatalogC3xx) and several servers can be connected. Due to the broad support of the Modbus standard, a wide range of devices can be considered for the server role.
Application examples
The range of applications extends from the connection of simple sensors to communication with drive and motor controllers to data exchange with complex measurement and control systems.
Energy management
- Milliseconds fast input for consumption meter inputs (energy, water, gas)
- Data acquisition from energy meters, PV systems, battery storage systems and transmission to a monitoring and control system
- Optimization of consumption / yields
Industrial control
- Control of simple equipment and assets
- Parameterizing remotely
- Switching / controlling actuators, motor controls
- Remote asset release
Water and wastewater treatment
- Capture sensor values
- Control and monitor metering pumps
Which operating modes does the Modbus library support?
The Modbus library is available for serial interfaces (RS232 and RS485) and Ethernet.
With regard to data transmission, three operating modes are distinguished:
Modbus RTU
- Transmits data in binary form
- good data throughput
- not readable by humans
Modbus ASCII
- Transmits data ASCII coded
- lower data throughput
- Directly readable by humans
Modbus TCP
- Similar to RTU
- Transmission in TCP/IP packets
- good data throughput
- not readable by humans
How the Modbus library works?
The Modbus Master Library enables easy integration of the Modbus protocol into your own projects.
For the integration of a Modubs client into the own project essentially five (Modbus RTU/ASCII) respectively seven (Modbus TCP) functions are required.
The library functions and handling are identical on all supported devices. The implementation of the hardware-specific features happens automatically in the background and thus ensures special comfort.
The library supports the master (=client) mode for serial interfaces (RS232 and RS485) as well as for Ethernet (LAN). In the case of the serial interfaces, data transmission can be optionally in the more efficient Modbus-RTU or alternatively in Modbus-ASCII format. Modbus TCP is used for Ethernet.
The following function codes for read or write access are currently supported:
Function code | Object type |
01 Read Coil Status | Read individual input “Coil” |
02 Read Input Status | Read individual input “Discrete Input” |
03 Read Holding Registers | Read (analogue) inputs “Holding Registers” |
04 Read Input Registers | Read (analogue) inputs “Input Registers” |
05 Write Single Coil | Einzelnen Ausgang „Coil“ schreiben |
06 Write Single Register | Write individual (analogue) output “Holding Register” |
15 Write Multiple Coils | Write multiple outputs “Coils” |
16 Write Multiple Coils | Write several (analogue) outputs “Holding Registers |
The library can be easily integrated and used in your own projects in the studio. In addition, the complete source code is available in the Studio.
Supported hardware
*cannot be used at the same time
The Modbus Master library is supported by the following IoT Devices with the corresponding interface ports:
myDatalogEasy IoT – 1x RS485 – 1x RS232 oder 1x RS4851) | myDatalogEasy IoTmini – 1x RS485 – 1x RS232 | myDatalogC3xx – 1xRS232 – 1xRS485 | M22x / M23x – 2xRS232 (UART0/1) 2) – 2xRS485 (SPI) 2) |
PoC RS485 2xRS485 | PoC RS232 1xRS232 | PoC LAN 1x LAN |
1) RS485 interface extension required
2) additional external wiring necessary