Reading registers with pymodbus

前端 未结 2 1440
忘掉有多难
忘掉有多难 2021-01-02 18:35

I am very new to Modbus and PyModBus however I have spent a good amount of time trying to read up and experiment with it. If anyone could point me in the right direction I

相关标签:
2条回答
  • 2021-01-02 18:46

    Try to:

     response = client.read_holding_registers(0x00,4,unit=1)
    

    where the unit value is device id of the slave.

    To print all:

    print response.registers
    

    Also is possible to directly get one value (for example third register):

    print response.getRegister(2)
    

    or

    print response.registers[2]  
    
    0 讨论(0)
  • 2021-01-02 18:49

    you could parse the response by yourself, the following is my code snippet:

        result = client.read_input_registers(0x01,1, unit=0x01)
        #print result
        t = result.registers[0]
        print "current temperature:", t, "  ", float(t/100.0)
    
    0 讨论(0)
提交回复
热议问题