1

I'm having some trouble reading registers from my WAGO 750-881 PLC using pymodbus, python 2.7, and Windows. I can read just fine with the Modbus Poll utility so I think the problem is in my python code. Using the following code I get the error: runfile('C:/Users/Mike/modbustest2.py', wdir='C:/Users/Mike') Exception Response(131, 3, IllegalValue)

from pymodbus.client.sync import ModbusTcpClient

c = ModbusTcpClient(host="192.168.1.20")
chk = c.read_holding_registers(257,10, unit = 1)
response = c.execute(chk)        
print response

I realize my code should read print response.registers but the .registers extension doesn't seem to be available to me. print response.registers throws this error: AttributeError: 'ExceptionResponse' object has no attribute 'registers' I only included the print response error because I thought it might be helpful in some way. Does anyone know what the problem may be?

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

1 Answers1

1

You're getting an ExceptionResponse object back, with the exception code 'IllegalValue'.

The most likely cause is you're reading a register the PLC doesn't think exists.

Of course there's no registers attribute on this object because it's not a ReadHoldingRegisters response.

Kevin Herron
  • 6,500
  • 3
  • 26
  • 35
  • I found the problem thanks to your help. For some reason if I try to read more than one register at a time, the program doesn't work. So if I write: `chk = c.read_holding_registers(257,1, unit = 1)` it doesn't throw an error. I am having another issue with the response giving me the wrong output but that's another question. I posted the other question [here](http://stackoverflow.com/questions/39418049/unexpected-number-when-reading-plc-using-pymodbus) – Mike C. Sep 09 '16 at 19:22