使用pymodbus读取PLC时出现意外的数字 [英] Unexpected number when reading PLC using pymodbus

查看:196
本文介绍了使用pymodbus读取PLC时出现意外的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用pymodbus读取Wago 750-881 PLC上的寄存器.我还在读取Modbus Poll实用程序和HMI上的相同寄存器. Modbus轮询和HMI均能正确读取,但pymodbus程序却无法读取.

I am using pymodbus to read a register on a Wago 750-881 PLC. I am also reading the same register on the Modbus Poll utility, as well as, an HMI. The Modbus Poll and HMI are reading correctly, but the pymodbus program is not.

这是代码:

from pymodbus.client.sync import ModbusTcpClient

c = ModbusTcpClient(host="192.168.1.20")
chk = c.read_holding_registers(257, 1, unit = 1)
response = c.execute(chk)        
print response.getRegister(0)

这是运行代码的响应:

>>> runfile('C:/Users/Mike/modbustest2.py', wdir='C:/Users/Mike')
18283

正确的输出应该是2043.它在其他寄存器上也读取相同的数字"18283".我知道问题一定与代码有关,因为我可以从其他程序/设备读取寄存器.任何帮助表示赞赏.

The correct output should be 2043. It also reads the same number "18283" on the other registers. I know the problem must be code related since I can read the register from other programs/devices. Any help is appreciated.

推荐答案

您可能正在读取错误的寄存器,读取错误的单元ID或两者的某种组合.

You may be reading the wrong register, or from the wrong unit ID, or some combination of both.

如果您使用Wireshark捕获第三方软件和您自己的软件正在做什么,那么您应该能够很快发现差异.

If you use Wireshark to capture what the 3rd party software and your own software is doing you should be able to spot the difference pretty quickly.

这篇关于使用pymodbus读取PLC时出现意外的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆