Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading registers with pymodbus

Tags:

python

modbus

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)

like image 873
5T4TiC Avatar asked Jul 21 '14 18:07

5T4TiC


2 Answers

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]  
like image 91
Azat Avatar answered Sep 27 '22 00:09

Azat


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)
like image 22
Jak Avatar answered Sep 27 '22 00:09

Jak