使用pymodbus从PLC读取故障

时间:2016-09-09 17:21:35

标签: python python-2.7 modbus plc modbus-tcp

我在使用pymodbus,python 2.7和Windows从WAGO 750-881 PLC读取寄存器时遇到了一些麻烦。我可以用Modbus Poll实用程序读得很好所以我认为问题出在我的python代码中。使用以下代码我收到错误: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

我意识到我的代码应该是print response.registers,但.registers扩展程序似乎无法使用。 print response.registers引发了此错误:AttributeError: 'ExceptionResponse' object has no attribute 'registers'我只包含print response错误,因为我认为它可能在某种程度上有所帮助。有谁知道问题可能是什么?

1 个答案:

答案 0 :(得分:1)

您将获得一个ExceptionResponse对象,异常代码为“IllegalValue”。

最可能的原因是您正在读取PLC认为不存在的寄存器。

当然这个对象没有register属性,因为它不是ReadHoldingRegisters响应。