问题
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