Unexpected number when reading PLC using pymodbus

谁都会走 提交于 2019-12-12 04:59:00

问题


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.

Here is the code:

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)

Here is the response from running the code:

>>> runfile('C:/Users/Mike/modbustest2.py', wdir='C:/Users/Mike')
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.


回答1:


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

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.



来源:https://stackoverflow.com/questions/39418049/unexpected-number-when-reading-plc-using-pymodbus

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!