Search code examples
python-3.xmodbuspymodbus

Pymodbus read register continuosly in read time fails


I have an intelligent sensor for measure robot axis movements, i would read valuesusing modbus for every single reading position (it read values every 100ms) I try using pymodbus:

slave = ModbusSerialClient(port='/dev/ttyAMA4', parity=N, baudrate=9600, timeout=1)
slave.connect()

while True:
    print(slave.read_input_registers(300013, 2, unit=10))
    time.sleep(0.01)

The problem is, my script start and read the first values but in 5,6 seconds exit because too many request to devices (devices does not respond) There is a method for call a modbus device and get values in "RealTime" for example every milliseconds without problem due to the hight volumes of continuosly calls?

So many thanks in advance


Solution

    1. Your code reads values at about every 10ms rather than 100ms. Typo?
    2. Since your purpose is to get values in "realtime", but how fast you can achieve mostly depends on the sensor, if you can find the specs from sensor datasheet, e.g. minimal polling interval, please code accordingly, otherwise, you can keep testing with different interval values until you are satisfied.