简体   繁体   中英

Reading registers with pymodbus

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 would appreciate it...


I have a drive with distance, velocity, acceleration, and deceleration on registers 40001, 40003, 40005, and 40007 (respectively). I was initially able to write to the distance register, using client.write_register(0000, n). After trying to write to velocity the drive started going haywire and faulting, and spinning 10x as fast as it should've been. However, the real priority is reading registers. I am trying to read the data from these registers and having zero luck. I tried using

request = client.read_holding_registers(0000,4)
response = client.execute(request)
print response


However, all I get back is "ReadRegisterResponse (0)".

So again, my big priority is trying to read values from these registers...any advice? (This is over TCP by the way)

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]  

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM