我正在使用 pymodbus 读取 Wago 750-881 PLC 上的寄存器。我还在 Modbus Poll 实用程序以及 HMI 上读取相同的寄存器。Modbus Poll 和 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)
这是运行代码的响应:
>>> runfile('C:/Users/Mike/modbustest2.py', wdir='C:/Users/Mike')
18283
正确的输出应该是 2043。它还在其他寄存器上读取相同的数字“18283”。我知道问题必须与代码相关,因为我可以从其他程序/设备读取寄存器。任何帮助表示赞赏。