What is Modpoll?
Modpoll It is an open-source command-line tool Modbus Main station simulator, From proconX The company is based on it FieldTalk™ Protocol stack development. It can be in Windows, Linux, QNX Wait for it to run on the operating system, It is carried out by engineers Modbus Equipment debugging, A powerful tool for protocol testing and batch data collection. With the belt GUI of Different Modbus Poll Completely controlled through command-line parameters, Modpoll Very suitable for integration into automated testing scripts and, In the process CI/CD Official download link.
Supported functions: http://www.focus-sw.com/fieldtalk/modpoll.html
Modpoll Transmission mode
- Serial port: Modbus RTU (And) Ethernet Modbus TCP (Simultaneously support passing) , Gateway communication RTU-over-TCP Function code coverage
- Reading coil: FC01 (Read discrete inputs) , FC02 (Read and hold registers) , FC03 (Read input register) , FC04 (Write a single coil) , FC05 (Write a single register) , FC06 (Write multiple coils) , FC15 (Write multiple registers) , FC16 (Read/write multiple registers) , FC23 (Data format)
- support: Decimal unsigned HEX, The decimal system has symbols, Floating point number, 32 Various display formats are available (Float) Byte order configuration
- support: And Big-Endian Two types of byte order Little-Endian Adapt to different manufacturers, Equipment PLC Polling mode
- Support single read and continuous polling: You can freely specify the polling interval, Output format
- Support standard text output and hexadecimal: Output two modes raw Installation
Platform installation Modpoll
Windows Download from the official website
Version of Windows Compressed package ZIP After decompression, it can be obtained, Executable file modpoll.exe Suggest adding the decompression directory to the system's. Suggest adding the decompression directory to the system's PATH In environmental variables, Convenient to call from any directory. Windows 10/11 Users can also directly access it WSL use Linux Version of Modpoll.
Linux Platform installation
# 下载 Linux 版本(以 3.10 版本为例)
wget http://www.focus-sw.com/fieldtalk/modpoll-3.10-linux-x86_64.tar.gz
# 解压
tar -xzf modpoll-3.10-linux-x86_64.tar.gz
# 进入目录
cd modpoll-3.10-linux-x86_64
# 测试运行
./modpoll --version
# 可选:创建软链接方便全局调用
sudo ln -s $(pwd)/modpoll /usr/local/bin/modpollARM / Embedded system Linux Installation
If needed on Raspberry Pi, etc ARM Running on the device, You can choose the corresponding option from the official website ARM edition, Or cross compile from source code. proconX Provided armhf And aarch64 Pre compiled packages for architecture.
Modpoll Detailed explanation of command-line parameters
| Parameters | meaning | Example |
|---|---|---|
-m | Transmission mode (tcp / rtu / ascii) | -m tcp |
-a | Slave station address (Slave ID) | -a 1 |
-r | Starting register/coil address (Protocol address) | -r 100 |
-c | The number of points read/written (Count) | -c 20 |
-b | Baud rate (RTU pattern) | -b 9600 |
-p | Checksum (none / even / odd) | -p none |
-t | Data type and display format | -t 4:hex |
-1 | Continuous polling mode | -1 |
-o | Timeout period (Seconds) | -o 3 |
-0 | Address from 0 Start (Default PLC Address from 1 Start) | -0 |
Common practical commands
1. Modbus TCP Read and hold registers (FC03)
From IP Address 192.168.1.100, Port 502 The equipment, Read the address of the slave station 1 Maintain registers 0-9 (Jointly 10 One) :
modpoll -m tcp -a 1 -r 1 -c 10 192.168.1.100Output examples:
-- Polling slave 1...
[1]: 1234
[2]: 5678
[3]: 0
[4]: 1002. Modbus RTU Serial communication
# Linux Platform(/dev/ttyUSB0)
modpoll -m rtu -a 1 -r 1 -c 10 -b 9600 -p none /dev/ttyUSB0
# Windows Platform(COM3)
modpoll -m rtu -a 1 -r 1 -c 10 -b 9600 -p none COM33. Continuous polling mode (For monitoring purposes)
# each 500 Millisecond polling once,infinite loop
modpoll -m tcp -a 1 -r 1 -c 20 -1 192.168.1.100 500
# Output polling data with timestamp
modpoll -m tcp -a 1 -r 1 -c 5 -1 192.168.1.100 1000 | while read line; do
echo "$(date '+%H:%M:%S') $line"
done4. Read the status of the coil (FC01)
# Read address 0 start 8 A coil
modpoll -m tcp -a 1 -r 1 -c 8 -t 0 192.168.1.100Note Indicate the type of coil: -t 0 Representing discrete inputs, -t 1 Representing input registers, -t 3 Represents holding registers, -t 4 Write into a single register.
5. Read (FC06)
# Address of the agreement 0 Write the register value of 1234
modpoll -m tcp -a 1 -r 1 192.168.1.100 12346. Floating point number 32 Floating point number (Float)
Many industrial instruments (Such as temperature transmitters, Flowmeter) Use two consecutive ones 16 The bit hold register stores one IEEE 754 32 Floating point number:
# From address 0 Start reading 2 A register,press float Format display
modpoll -m tcp -a 1 -r 1 -c 2 -t 4:float 192.168.1.1007. Batch writing to multiple registers (FC16)
# From the protocol address 0 Start,Write sequentially 100, 200, 300, 400
modpoll -m tcp -a 1 -r 1 192.168.1.100 100 200 300 4008. Read write combination operation (FC23)
# Read address 0-4(5A register),Simultaneously provide the address 10-11 write 99, 88
modpoll -m tcp -a 1 -r 1 -c 5 -w 11 -q 2 192.168.1.100 99 88Integrate into automated testing scripts
Modpoll The command-line feature makes it an ideal choice for automated testing. The following is a complete device acceptance testing script:
#!/bin/bash
# Modbus 设备寄存器读写验收测试
# 用法: ./modbus_test.sh <设备IP>
DEVICE_IP=${1:-"192.168.1.100"}
PASS=0
FAIL=0
echo "=== Modbus 设备验收测试 ==="
echo "目标设备: $DEVICE_IP"
echo ""
# 测试1: TCP 连接性
echo "[TEST 1] TCP 端口 502 连通性"
if timeout 3 bash -c "echo > /dev/tcp/$DEVICE_IP/502" 2>/dev/null; then
echo " [PASS] 端口 502 可达"
PASS=$((PASS+1))
else
echo " [FAIL] 端口 502 不可达"
FAIL=$((FAIL+1))
fi
# 测试2: 读取保持寄存器 FC03
echo "[TEST 2] 功能码 FC03 - 读保持寄存器"
result=$(modpoll -m tcp -a 1 -r 1 -c 5 -o 1 $DEVICE_IP 2>&1)
if echo "$result" | grep -qE '[[0-9]+]:'; then
echo " [PASS] FC03 功能正常"
PASS=$((PASS+1))
else
echo " [FAIL] FC03 读取失败: $result"
FAIL=$((FAIL+1))
fi
# 测试3: 写入保持寄存器 FC06
echo "[TEST 3] 功能码 FC06 - 写单寄存器"
# 先读当前值
before=$(modpoll -m tcp -a 1 -r 1 -c 1 -o 1 $DEVICE_IP 2>&1 | grep -oP '(? /dev/null 2>&1
# 验证写入
after=$(modpoll -m tcp -a 1 -r 1 -c 1 -o 1 $DEVICE_IP 2>&1 | grep -oP '(? /dev/null 2>&1
if [ "$after" = "9999" ]; then
echo " [PASS] FC06 写入功能正常"
PASS=$((PASS+1))
else
echo " [FAIL] FC06 写入失败: 预期9999, 实际$after"
FAIL=$((FAIL+1))
fi
echo ""
echo "=== 测试结果: $PASS 通过, $FAIL 失败 ==="Modpoll Compared to others Modbus Tool comparison
- Modbus Poll: Windows GUI Tools, Visual operation, Suitable for manual debugging. Official website www.modbustools.com.
- Modpoll: Pure command-line tool, Cross platform, Suitable for script automation and remote deployment, Completely free.
- pymodbus: Python Library, Programming is required, The highest flexibility, Suitable for building custom testing frameworks.
- QModMaster: Qt Cross platform writing GUI Tools, Open source and free, The function is relatively simple.
Guidelines for troubleshooting common problems
Connection timeout
Firstly, use ping Confirm network layer connectivity. For Modbus TCP, Default use 502 Port, Use telnet 192.168.1.100 502 Testing. If the connection is immediately disconnected (Rather than timeout) , The server refused the connection, Possible port not open. If there is no response after waiting indefinitely, Possible firewall interception.
Read all values as zero
Possible reasons: Slave station address -a The settings do not match the actual device; Starting address -r of Address to protocol address conversion error PLC Like (Address PLC Corresponding protocol address 40001 This register is indeed not configured or has not been written with data 0) ; Mode returns exception/error.
RTU Confirm one by one
Baud rate: Data bits (-b) , Fixed 8-bit (Fixed 8-bit) , Checksum (-p: none/even/odd) Is the stop position consistent with the slave device. RS-485 Pay special attention to wiring A (+) /B (-) The line sequence cannot be reversed. Suggest using an oscilloscope or logic analyzer to observe the signal quality on the bus first.
Floating point number reading abnormal
32 Floating point numbers involve two 16 The arrangement order of bit registers (Byte order/Word order) . Different manufacturers may use it ABCD, CDAB, BADC, DCBA Wait in different orders. Modpoll Default use Big-Endian Floating point format. If the reading is significantly abnormal (Like NaN Or the order of magnitude is completely incorrect) , Try using modpoll -t 4:hex First, look at the original hexadecimal value, Manually calculate and confirm the byte order before adjusting the configuration.
Summary
Modpoll Yes Modbus The indispensable "Swiss Army Knife" in the protocol debugging toolchain". its biggest advantage lies in its lightweight, cross platform, command-line driver, seamless integration, scripting, testing framework, and assembly line, whether it is embedded engineers verifying microcontrollers, slaves, automation engineers debugging, communication configuration, or engineers writing automation, equipment acceptance testing, mastery Shell all can significantly improve work efficiency, Python Testing framework and CI/CD pipeline. Whether it's an embedded engineer verifying a microcontroller Modbus slave, Automation engineer debugging PLC Communication Configuration, still QA Engineers write automation Modbus Equipment acceptance testing, master Modpoll Can significantly improve work efficiency.
Leave a Reply