介绍

modpoll是一款小巧的支持串口以及网口的modbus通信测试工具,无缝衔接Linux && Windows系统,非常适合命令行调试使用,在工业控制、自动化、物联网领域很受欢迎!

应用

以在Linux下测试modbus tcp slave为例,按照惯例,先测试跟从机的通信是否正常

1
telnet 192.168.55.10 502

命令参数用法

  • -m tcp:TCP 模式
  • -a 1:从站地址 1
  • -r 11:起始寄存器(modpoll 默认 1-based,代码里 10 要写 11)
  • -c 1:数量 1
  • -t 4:保持寄存器(Holding Register)
  • 192.168.55.142:目标IP地址
  • 1 或 0:要写入的值

寄存器类型(通过-t参数指定)

-t 寄存器类型 用法示例
0 线圈 modpoll -m tcp -a 1 -r 1 -c 10 -t 0 192.168.55.142
1 离散输入 modpoll -m tcp -a 1 -r 1 -c 10 -t 1 192.168.55.142
3 输入寄存器 modpoll -m tcp -a 1 -r 1 -c 10 -t 3 192.168.55.142
4 保持寄存器 modpoll -m tcp -a 1 -r 11 -c 1 -t 4 192.168.55.142

设备信息

总线上挂载的从站N的设备信息

1
modpoll -m tcp -a N -t id xx.xx.xx.xx

写入

写保持寄存器,怎么读取寄存器的值,value一般放在IP地址后面

1
modpoll -m tcp -a 1 -r 11 -c 1 -t 4 xx.xx.xx.xx value

读取

读保持寄存器(IP地址之后不跟参数说明需要读取)

1
2
3
4
5
# 读取单个寄存器
modpoll -m tcp -a 1 -r 21 -c 1 -t 4 xx.xx.xx.xx

# 读取两个寄存器
modpoll -m tcp -a 1 -r 31 -c 2 -t 4 xx.xx.xx.xx

指定读取的数据格式:hex、i32、f32、f64

1
2
3
4
modpoll -m tcp -a 1 -r 31 -c 2 -t 4:hex xx.xx.xx.xx
modpoll -m tcp -a 1 -r 31 -c 2 -t 4:i32 xx.xx.xx.xx
modpoll -m tcp -a 1 -r 31 -c 2 -t 4:f32 xx.xx.xx.xx
modpoll -m tcp -a 1 -r 31 -c 4 -t 4:f64 xx.xx.xx.xx

『 下里巴人 』
海纳百川,文以载道
hywing技术自留地
总访问 113701 次 | 本页访问 326