Reading registers with pymodbus

5T4TiC picture 5T4TiC · Jul 21, 2014 · Viewed 25.5k times · Source

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)

Answer

Azat picture Azat · Jul 29, 2014

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]