I have some modbus TCP code written under pymodbus 1.2
the relevent code was
result = modbus_client.read_holding_registers(40093, 3)
After updating to pymodbus 1.4.0 it wouldn't work until I cargo culted the new unit parameter into the function call (teh examples all had unit=1 in
them):
result = modbus_client.read_holding_registers(40093, 3, unit=1)
what does the unit parameter in pymodbus read_ holding_registers() mean?
I can't seem to find an explanation anywhere.
The source says ":param unit: The slave unit this request is targeting",
but I don't understand what this means, nor what selection other than 1 might be used.
The Modbus protocol was originally developed long before TCP/IP was popular (late 70s I think). It was used on serial connections mostly. Some serial hardware protocols like RS485 allow daisy-chaining. The modbus master (in your case Python) can poll many slaves on a single serial port. Only the slave that was requested will respond. The address of the slave is the Unit in this case. Once Modbus was adapted to TCP/IP, the protocol allowed this "unit address" to be used to create multiple slaves behind a single IP address. Most of the time, if using TCP/IP there is a single address of 1. On Wikipedia they refer to this as "Station address."
I'm not sure why you would need to include this in the call to the method since it is a kwarg that is defaulted to 1 anyway.
What does the pymodbus "unit" parameter mean?