I have discovered a nice CLI tool called mbpoll than can be used for fast Modbus wiring validation via CLI. It is very handy for anything that has an Ethernet port for the ModbusTCP, including devices like Raspberry Pi based controllers industrial controllers.

Additionally, if any kind of RS485 interfacing is available, then it can be used for ModbusRTU as well. I was successfully able to use it with a cheap CH340 chip based USB-to-RS485 dongle and with RevPi Connect with its integrated RS485 terminals.

Compiling mbpoll on Raspberry Pi 4

Although the mbpoll is not available from the standard repositories, the README does well enough job explaining what to do, with some twists. In short:

sudo apt-get install cmake pkg-config libmodbus-dev
git clone https://github.com/epsilonrt/mbpoll.git
cd mbpoll
mkdir build
cd build
cmake ..
make package
sudo dpkg -i mbpoll_1.4.25_armhf.deb

The condition for this is that libmodbus-dev is >= v3.1.4. At the time of writing, on my device, it was at this exact version, so no problems here. It is possible to check beforehand:

apt-cache show libmodbus-dev

Otherwise, compiling libmodbus from source is required as well.

Example commands

To set the coil 4 (3 on devices that start counting from 0) on the device with Modbus address 7 to the state HIGH with the USB dongle, this command can be used:

mbpoll -t 4 -a 7 -b 9600 -P none /dev/ttyUSB0 1

For the completeness, to set the same coil to the state LOW:

mbpoll -t 4 -a 7 -b 9600 -P none /dev/ttyUSB0 0

Both commands assume that the slave is a ModbusRTU device, communicating with the 9600 baud rate with the options 8N1. For the record, the ModbusRTU slave used was Qiudo RS 8/8.

This is a 90th post of #100daystooffload.