Modbus实用小工具合集:RTU/TCP解析器、串口扫描器与命令行测试技巧

freeFree Technical Resource

This content is free to read, suitable for basic learning and search traffic.

Modbus实用小工具合集:RTU/TCP解析器、串口扫描器与命令行测试技巧

Modbus 调试中的"瑞士军刀"

在日常的 Modbus 设备调试中,并非每次都需要打开 Wireshark 抓包或者写 Python Script。有时候你只需要快速验证一个功能——解码一串十六进制报文、扫描一个未知设备的寄存器范围、或者在命令行里测试一个读写请求。本文汇总了 modbus.org 推荐的那些最轻量、最实用的 Modbus 小工具。

Modbus RTU/TCP 报文在线解析器

当你从串口助手收到一串 Modbus message,或者在代码里调试时打印了一段 Modbus 二进制数据,你需要快速知道这段数据是什么意思。在线 Modbus 报文解析器是最快的解决方案——不需要安装任何软件,浏览器打开即可使用。

在线 Modbus RTU Parser

Recommended Tools:CAS Modbus RTU Parser(Chipkin 자동화 Systems 提供)

访问:store.chipkin.com/products/tools#modbus-rtu-parser

这是一个纯网页工具。你只需粘贴一串十六进制 Modbus RTU message:

01 03 00 00 00 0A C5 CD

Click解析后,工具会自动展示:

  • slave 주소(Slave ID)= 1
  • 기능 코드 = 03(Read Holding 회원가입s)
  • 시작ing 주소 = 0
  • 请求数量 = 10 레지스터s
  • CRC 검증 = 0xCDC5(并验证是否正确 ✓)

在线 Modbus TCP Parser

访问:store.chipkin.com/products/tools#modbus-tcp-parser

与 RTU 版本类似,但增加了 MBAP 头的解析:Transaction ID、Protocol ID、Length 和 Unit ID。粘贴如下 TCP 报文即可:

00 01 00 00 00 06 01 03 00 00 00 0A

parsing result:事务 ID=1,Protocol=Modbus,slave=1,기능 코드=03,시작ing 주소=0,Quantity=10。

Modbus 设备地址空间扫描工具

CAS Modbus Scanner

下载地址:store.chipkin.com/products/tools/cas-modbus-scanner

当你拿到一个没有完整寄存器映射手册的 Modbus 设备时,最直接的方法就是"扫描"——用 Modbus Scanner 遍历设备的地址空间,记录下哪些地址返回了有效数据。

使用方法

  1. 设置连接方式(TCP 输入 IP:Port,RTU Select 시리얼 포트)
  2. 选择要扫描的地址范围(建议先小范围 0-100 试探)
  3. 选择要扫描的数据类型:线圈、离散输入、保持寄存器、输入寄存器
  4. Click Start Scan,观察结果
  5. 对返回有效数据的地址做好记录
  6. 结合设备实物(改变物理量、观察对应寄存器变化)进行验证

扫描技巧

  • 先扫描保持寄存器(4xxxx),因为大多数设备的配置和测量数据都在这里
  • 如果某个地址返回异常码 02(Illegal 데이터 주소),说明该地址无效
  • 如果返回 0 但无异常,需要判断是真的值=0 还是设备对该地址没有实现(仅靠扫描无法区分)
  • 改变物理激励(如升温、旋转编码器)后复扫,观察哪些地址值发生变化

命令行协议测试:modbus-cli 技巧

除了专用工具外,很多通用的命令行工具也可以用于 Modbus 测试:

用 Netcat 测试 TCP 连通性

# 测试 Modbus TCP 设备是否在线
nc -zv 192.168.1.100 502

# 如果输出 "Connection to 192.168.1.100 502 port [tcp/*] succeeded!" 说明在线

用 Python 一行命令测试

# 安装 pymodbus 后,一行测试读取保持寄存器
python3 -c "
from pymodbus.client import ModbusTcpClient
c = ModbusTcpClient('192.168.1.100')
c.connect()
rr = c.read_holding_registers(0, 5, slave=1)
print('Values:', rr.registers if not rr.is오답() else rr)
c.close()
"

用 xxd 分析二进制 Modbus 데이터

# 如果你有一段 Modbus 二进制数据文件,可以用 xxd View
xxd modbus_dump.bin

# 或者用 hexdump 格式化显示
hexdump -C modbus_dump.bin | head -20

Modbus protocol函数快速参考

调试时经常需要查功能码对应表,以下是常用功能码速查:

기능 코드이름데이터 type작업
01 (0x01)Read Coils线圈(0xxxx)读 1-bit
02 (0x02)Read Discrete Inputs离散输入(1xxxx)读 1-bit
03 (0x03)Read Holding 회원가입s保持寄存器(4xxxx)读 16-bit
04 (0x04)Read Input 회원가입s输入寄存器(3xxxx)读 16-bit
05 (0x05)Write Single Coil线圈写 1-bit
06 (0x06)Write Single 회원가입保持寄存器写 16-bit
15 (0x0F)Write Multiple Coils线圈写多 1-bit
16 (0x10)Write Multiple 회원가입s保持寄存器写多 16-bit
23 (0x17)Read/Write Multiple 회원가입s保持寄存器读写组合

Modbus 异常码速查

Exception Code含义常见原因
01非法功能码设备不支持该功能码
02Illegal 데이터 주소请求的地址范围超出设备可用范围
03Illegal 데이터 value写入的值超出允许范围
04Substation equipment malfunction设备内部错误,无法处理请求
05Confirm(ACK)请求已接受但需要较长时间处理
06The slave station equipment is busy设备正忙,稍后重试

总结

Modbus 调试不需要每次都用重型工具。在线解析器适合快速解码报文、扫描器适合逆向未知设备的寄存器映射、命令行工具适合自动化测试。掌握这些"小工具"能让你的 Modbus 调试效率翻倍——遇到问题先用最轻量的工具定位,只有当需要深入分析时才动用 Wireshark 等重型工具。

Put this resource to use in a real project?

Go to the Tool Center for message parsing, CRC 검증 and device debugging, or submit your requirements for selection and integration advice.

Engineer Membership

Turn this article into actionable debugging resources

After activation, you can use advanced message parsing, resource pack downloads, code examples, engineering cases and priority technical support, suitable for real project delivery.

Unlimited Advanced Tools
Resource & Code Packs
Complete Engineering Case Library
Priority Technical Support

Leave a Reply

Your email 주소 will not be published. Required fields are marked *.