使用pymodbus读取寄存器

时间:2016-09-09 14:09:17

标签: python modbus-tcp

我试图使用pymodbus从PLC读取modbus寄存器。我正在关注发布here的示例。当我尝试print.registers时,出现以下错误:object has no attribute 'registers' 该示例未显示正在导入的模块,但似乎是接受的答案。我认为错误可能是我导入错误的模块或者我错过了一个模块。我只是想读一个寄存器。

这是我的代码:

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.registers

1 个答案:

答案 0 :(得分:0)

从阅读the pymodbus code开始,read_holding_registers对象的execute方法似乎会返回 响应对象和{ {1}}包含错误的对象。我猜你会收到后者。你需要尝试这样的事情:

ExceptionResponse