使用pymodbus读取PLC时出现意外数字

2024-04-29 13:21:43 发布

您现在位置:Python中文网/ 问答频道 /正文

enter image description here我正在使用pymodbus读取Wago 750-881 PLC上的寄存器。我还在Modbus轮询实用程序以及HMI上读取相同的寄存器。Modbus轮询和HMI读取正确,但pymodbus程序不正确。在

代码如下:

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)

响应从这里运行:

^{pr2}$

正确的输出应该是2043。它还读取其他寄存器上相同的数字“18283”。我知道问题一定与代码有关,因为我可以从其他程序/设备读取寄存器。感谢任何帮助。在


Tags: 代码from程序实用程序clientresponsesync寄存器