Practicing the Modbus RTU Industrial Communication Protocol

Published 2025-04-19

Updated 2025-04-23

Notes from using RS485 + Modbus RTU for business data transmission in a desktop/client application.

Written by - kok-s0s

Qt

C++

Qt

Host Computer

After reviewing the work, there was actually nothing especially difficult. It was just that in the DDD domain-driven development context of industrial automation, some technical terms in this field were still unfamiliar to me. Starting development directly came with a little confusion. The RS485 physical-layer protocol itself is quite simple. In fact, as an upper-computer application developer, I do not need to care too much about the physical-layer details. The key is how to use the Modbus industrial communication protocol according to the business requirement.

The latest term for the RS485 physical-layer protocol on Wikipedia is now EIA-485.

Why

The application I am currently developing needs to connect to an external hardware device. Data interaction between the application and the device happens through the RS485 protocol, which belongs to the physical layer in the OSI model.

Goal

The goal is to make data interaction between the application and hardware device work: complete data sending and receiving, then implement the related business features. The confusing part was data send/receive processing. The business feature development itself was much simpler.

Learning by Analogy + ChatGPT

As the master side of communication, the application uses a company-encapsulated SDK interface to read and write device registers through the ModbusRTU protocol.

As the slave side of communication, the device uses ModbusRTU classes from the Qt ecosystem to read and write device registers.

Both sides are essentially using the ModbusRTU industrial communication protocol.

In the whole data interaction development process, I only used function code 0x03, Read Holding Registers, and function code 0x10, Write Multiple Registers.

I also became familiar with how the Qt ecosystem uses the ModbusRTU protocol through QModbusRtuSerialSlave.

The rest was mainly learning through Q&A with ChatGPT and modifying code.

Notes from GPT Q&A and My Understanding

Modbus is a communication protocol widely used in industrial automation. It is mainly used for data exchange between industrial devices such as PLCs, sensors, frequency converters, instruments, and so on.

Industrial Properties of Modbus

PropertyDescription
Design intentDesigned for industrial environments, emphasizing simplicity, reliability, and real-time behavior.
Typical scenariosFactory automation, SCADA systems, power monitoring, building control, etc.
Hardware compatibilitySupports RS485, RS232, and Ethernet through Modbus TCP, adapting to industrial field wiring.
Protocol simplicityCompact frame structure, easy for embedded devices to implement, suitable for resource-limited industrial controllers.
Master-slave architectureSuitable for centralized monitoring in industrial control, such as a PLC as master and sensors/actuators as slaves.

Industrial Application Examples of Modbus

Limitations of Modbus

Comparing Modbus with Other Industrial Protocols

ProtocolLayerCharacteristicsSuitable scenarios
ModbusApplication layerSimple, general-purpose, low costSmall and medium industrial control systems
PROFINETReal-time EthernetHigh speed and deterministic latencyHigh-performance automation, such as automotive manufacturing
EtherCATReal-time EthernetDistributed clocks and ultra-low latencyPrecision motion control, such as robotics
CANopenData link layerStrong anti-interference and multi-master architectureVehicles and engineering machinery

End

I have now entered one more knowledge domain. When I run into similar problems later, they should be much easier to handle.