Modbus Comm.

Posted by Yifan Wang on 02 September, 2021

Modbus is a widely used simple and reliable protocol for SCADA systems in many industries. It follows master-slave mechanism. If there are multiple slave devices, daisy chain method could be used.

Two popular variants of Modbus are Modbus RTU and Modbus TCP. The most basic difference between Modbus RTU and Modbus TCP is that Modbus TCP runs on an Ethernet physical layer and Modbus RTU is a serial protocol [1].

Modbus RTU is used in my monitoring and control project. Modbus RTU can run over RS232 or RS485 [2]. RS485 is common as it allows multi-dropping and longer communication distance. Typical RS485 cable types can be referred here [3]. The following pic shows the RJ45 serial to USB cable in my project. The USB end has the RS485 to USB adapter which allows convenient connection to the laptop or remote devices.

Modbus Ethernet Cable

A bit about the Modbus data

There are only two data types in Modbus: coils (1-bit, input or output, indicating ON and OFFs) and registers (16-bit, Input Registers and Holding Registers, for storing numerical values). Input Registers store the state of input and normally read only. Holding Registers can be used for digital outputs or setting parameters.

How can I not mention Python implementation

Two popular python packages for Modbus: pymodbus and minimalmodbus. The following picture shows some successful data received from the charger controller after some trouble shooting. Script is written in Python using minimalmodbus and run in the Raspberry Pi 2 Model B (one of my old buddies that has run many of my previous projects strongly).

Modbus Python Programming

Stay tuned for the next outcomes!

[1]https://www.rtautomation.com/technologies/modbus-rtu/

[2]https://www.lammertbies.nl/comm/info/rs-485

[3]https://ctlsys.com/support/rs-485_cables_for_bacnet_and_modbus/