I'm using ModbusSerialClient of pymodbus library. I've multiple registers that I want to read.
I'm able to read one register at a time, but not able to figure out how to read all the registers at a single time for better performance.
registers = [3900,3902,3904,3906,3926,3860]
client = ModbusSerialClient(method='rtu',port='/dev/ttyUSB0', timeout=1, parity='N', baudrate=19200, unit=1)
client.connect()
for register in registers:
response = client.read_holding_registers(register, 2, unit=0x01)
I've tried something like this
add_min, add_max = min(registers), max(registers)
no_bytes = add_max - add_min
response = client.read_holding_registers(add_min, no_bytes, unit=0x01)
But it's throwing "Illegal Address" error.
1 register == 2 bytes
) If you are trying to read more than 125 registers pymodbus would throwInvalidAddress
exception. Make sure1< no_bytes<=125
.no_bytes = (add_max - add_min) + 2
instead ofno_bytes = add_max - add_min
, because in the maximum registers you need also to read two count. And consider maximum count of reading that not be more that125
in each request.