使用python在Modbus中读取响应消息

时间:2018-10-12 06:29:37

标签: python modbus pymodbus

我正在尝试在pymodbus模块的帮助下使用python通过modbus发送查询并获取响应消息(数据)。

response=client.read_holding_registers(19200,126,unit=135)    
print(response) 

正在打印的响应是发送的请求消息和过程状态。我有兴趣读取从站发送的数据,而不是进程状态。你能帮我吗?

1 个答案:

答案 0 :(得分:0)

您应该使用.registers

请尝试以下过程:

response = client.read_holding_registers(19200, 126, unit=135)    

if not response.isError():
    print(response.registers)

else:
    # Handle Error 

[注意]:

  • .isError()方法适用于 pymodbus 1.4.0 及更高版本。