Modbus Master Library – simple, convenient implementation

Modbus is a communication protocol commonly used in industrial automation. The Modbus protocol consists of a client-server architecture in which a client (for example, a control device) sends commands to a server (for example, sensors or actuators) and receives data from it.

The communication is based on a simple command-response mechanism. Modbus is an open protocol, which among other things has led to its great popularity and spread.

Table of Contents

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
Blog_What is Modbus

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.

Library Modbus TCP

* Returns the data requested by MBM_Read ( ) as soon as they have been sent by the Modbus server.

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

Blog Modbus-Master Library

*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
myDatalogEasy IoT
– 1x RS485
– 1x RS232 oder 1x RS4851)
myDatalogEASY_IoT_mini
myDatalogEasy IoTmini
– 1x RS485
– 1x RS232
myDatalogC3xx
myDatalogC3xx
– 1xRS232
– 1xRS485
rapidM2M M22x 2G/4G EU
M22x / M23x
– 2xRS232 (UART0/1) 2)
– 2xRS485 (SPI) 2)
rapidM2M PoC RS485
PoC RS485
2xRS485
rapidM2M PoC RS232
PoC RS232
1xRS232
rapidM2M PoC LAN
PoC LAN
1x LAN

1) RS485 interface extension required

2) additional external wiring necessary

Would you like to learn more about Microtronics?

Uplink NB-IoT - Data connection
Blog

NB-IoT as uplink

At the latest since 2G and 3G switch-offs were announced and in some cases have already become reality, the M2M/IoT

4G is not always 4G
Blog

4G is not always 4G

The term 4G is well known. You often read and hear it in connection with mobile radio and transmission technology. But what exactly is meant by the term? What is the difference to other terms such as LTE or NB-IoT and why do people still talk about 4G when there is actually already 5G?

In order to use our live chat, you must agree to the loading of Hubspot cookies. You can find out more about this in our privacy policy.