modbus-debug
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseModbus 调试
Modbus Debugging
适用场景
Application Scenarios
- 嵌入式设备实现了 Modbus RTU/TCP 从站,需要验证通信是否正常。
- 需要读写保持寄存器、输入寄存器、线圈或离散输入。
- 需要扫描总线上的从站地址,确认设备是否在线。
- 需要持续监控寄存器值的变化。
- The embedded device implements Modbus RTU/TCP slave, and needs to verify whether the communication is normal.
- Need to read/write holding registers, input registers, coils or discrete inputs.
- Need to scan slave addresses on the bus to confirm whether the device is online.
- Need to continuously monitor changes in register values.
必要输入
Required Inputs
- RTU 模式:串口号(如 COM42)、波特率、从站地址。
- TCP 模式:主机 IP 和端口、从站地址。
- 操作类型:读/写/扫描/监控。
- RTU mode: serial port number (e.g. COM42), baud rate, slave address.
- TCP mode: host IP and port, slave address.
- Operation type: read/write/scan/monitor.
依赖
Dependencies
- (pip install pymodbus)
pymodbus - (RTU 模式需要)
pyserial
- (pip install pymodbus)
pymodbus - (required for RTU mode)
pyserial
执行步骤
Execution Steps
- 先阅读 references/usage.md,确认操作参数。
- 探测环境:
bash
python scripts/modbus_tool.py --detect - 根据需求执行对应操作:
bash
# 读保持寄存器 python scripts/modbus_tool.py --port COM42 --slave 1 --read --address 0 --count 10 # 写寄存器 python scripts/modbus_tool.py --port COM42 --slave 1 --write --address 0 --values 100,200 # 扫描从站 python scripts/modbus_tool.py --port COM42 --scan --scan-range 1-10 # TCP 读取 python scripts/modbus_tool.py --tcp --host 192.168.1.100 --slave 1 --read --address 0 --count 10
- First read references/usage.md to confirm the operation parameters.
- Detect the environment:
bash
python scripts/modbus_tool.py --detect - Execute the corresponding operation according to requirements:
bash
# Read holding registers python scripts/modbus_tool.py --port COM42 --slave 1 --read --address 0 --count 10 # Write registers python scripts/modbus_tool.py --port COM42 --slave 1 --write --address 0 --values 100,200 # Scan slaves python scripts/modbus_tool.py --port COM42 --scan --scan-range 1-10 # TCP read python scripts/modbus_tool.py --tcp --host 192.168.1.100 --slave 1 --read --address 0 --count 10
失败分流
Failure Branches
- :串口无法打开、网络不通。
connection-failure - :从站地址无响应。
slave-no-response - :设备不支持该功能码。
illegal-function - :寄存器地址越界。
illegal-address
- : Serial port cannot be opened, network is unreachable.
connection-failure - : No response from slave address.
slave-no-response - : The device does not support this function code.
illegal-function - : Register address is out of bounds.
illegal-address
输出约定
Output Convention
示例输出格式:
结果: ✅ 读取 10 个寄存器
连接: RTU COM42 9600 8N1
从站: 1
地址 | 十进制 | 十六进制 | 二进制
------+---------+----------+--------------------
0 | 100 | 0x0064 | 0000000001100100
1 | 200 | 0x00c8 | 0000000011001000Example output format:
Result: ✅ Read 10 registers
Connection: RTU COM42 9600 8N1
Slave: 1
Address | Decimal | Hexadecimal | Binary
------+---------+----------+--------------------
0 | 100 | 0x0064 | 0000000001100100
1 | 200 | 0x00c8 | 0000000011001000交接关系
Handover Relationships
- 从 /
build-keil烧录固件后,用此 skill 验证 Modbus 通信。build-platformio - 与 互补:serial-monitor 查看串口原始输出,modbus-debug 进行协议级调试。
serial-monitor
- After burning firmware with /
build-keil, use this skill to verify Modbus communication.build-platformio - Complementary to : serial-monitor views raw serial port output, modbus-debug performs protocol-level debugging.
serial-monitor