pymodbus: request creation and response receiving

自作多情 提交于 2019-12-02 00:57:11

You could execute dir(response) to check what the response is composed of but if pymodbus TCP master is similar to RTU serial master implementation then the data is available in Registers field so try to print response.Registers instead of response. The response.Registers should be a one-element array containing the value of register your requested for reading.

Set the unit argument and use the print(request.registers) instead of print(request).

Here's an example:

request = client.read_holding_registers(4138, 1, unit=1)  # Notice: Set the unit argument.

if not request.isError():
    '''isError() method implemented in pymodbus 1.4.0 and above'''

    print(request.registers)  # Your problem is here.

else:
    # Do stuff to error handling.
    print('Error message: {}'.format(request))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!