Modbus is a communication protocol commonly used in industrial automation systems, smart home systems, automated networks of small objects (warehouses, greenhouses, etc). The protocol serves for connecting equipment of various types to a home computer as well. The development of such projects as Arduino and Raspberry Pi has significantly increased interest in tasks related to robotics and automation. All this ensures the growth of Modbus popularity among amateurs and professionals.
In this article, we'll cover the key features of the existing software and hardware solutions for testing and debugging devices and networks based on Modbus protocol.
If you are familiar with the architecture of the protocol, you can jump right to the description of Modbus software. If not, below you will find a short introduction into Modbus.
Table of content:
About Modbus protocol
Modbus is a common protocol used in automation systems at the middle and lower (field) levels. The middle level is the level of controllers - devices that collect data and control the technological process. The field level is the level of interaction between sensors and controllers or sensors and the server.
The typical structure of an automation system that uses Modbus as its basic protocol is shown below.
The standard 'environment' for Modbus protocol is RS485/422/232. Modbus RTU or Modbus ASCII work over it. In TCP/IP networks, however, the higher-level protocol is TCP transport protocol and this variant is called Modbus TCP. In this article, we'll talk about Modbus RTU transmission mode.
Modbus protocol is implemented using a master-slave relationship. That means communication is always initiated by one device, the master, which sends a request to a slave (server) and waits for a response. There is always one master on the network and from 1 to 247 slaves.
The master interacts with slave devices in the request-response format. The request contains a sequence of bytes, called a frame, in which the time between bytes is standardized depending on the data transfer rate and is no longer than the interval during which 1.5 bytes of data can be transmitted. In RTU mode, messages start with a silent interval of at least 3.5 character times.
A request message is sent in the following format:
ID - device address (1 byte),
FN - Modbus function (1 byte),
[args] - function arguments (N bytes, depending on the function),
CRC - a checksum CRC-16 (2 bytes).
The format of a response message:
As you can see, the response and request frames have similar constructions, except for the Data field, which provides different content depending on the function performed.
In case the requested function is not supported by the slave device or the arguments in the [args] field of the request are incorrect for this server, in the FN field of the response the high bit will be set to 1 and the Data field will contain additional information on the error occurred.
Also, particular slave devices can have specific registers with additional information.
The types of registers referenced in Modbus devices include the following:
|Discrete Inputs||used as inputs|
|Coils Outputs||used to control discrete|
|Input registers||used for input|
|Holding registers||used for a variety of things including inputs, outputs, configuration data, etc.|
The full description of the Modbus RTU protocol is provided in its functional specification.
When setting up a Modbus network, a point to consider is that the protocol enables the transmission of data from multiple devices that are to be received by a single server or controller that has a Modbus driver installed. A serial app can control a server’s communication port (ex. COM1) as it receives Modbus data from multiple sensors.
Unfortunately, there is a limitation, as opening the receiving port in multiple applications simultaneously can pose a significant challenge.
There is a solution to this dilemma. Virtual COM Port Driver PRO by Eltima allows the creation of virtual RS485 ports and the splitting of Modbus data so multiple ports can receive the data at the same time.