0

enter image description hereI 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.

Mike C.
  • 1,761
  • 2
  • 22
  • 46

1 Answers1

0

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.

Kevin Herron
  • 6,500
  • 3
  • 26
  • 35
  • I added a picture of the Modbus Poll. – Mike C. Sep 09 '16 at 22:47
  • Have you tried reading +/- 1 from this address, as well as tried reading 40257 instead of 257? I am not familiar with the Modbus Poll utility you're using so I can't be certain about what it's actually doing vs what your Python code is doing. Wireshark would be ideal. – Kevin Herron Sep 09 '16 at 23:36
  • @mikec. did you ever figure this out? – Kevin Herron Sep 12 '16 at 03:21
  • I just abandoned the module. I went with modbus_tk and got it to working in 15 minutes. – Mike C. Sep 12 '16 at 14:05