I am using the libmodbus libraries to communicate with a solar inverter with a Modbus interface (SMA). The Modbus specification document specifies that a certain Unit ID should be used to read registers on the device. The device offers a TCP interface for modbus.
I can't find the code to change the Unit ID for the libmodbus libraries. Is it the modbus_set_slave() function? Or is there another functions that I am missing here?
I believe it is the modbus_set_slave() function although the terminology is different. Conceptually either Slave ID or Unit ID is acceptable terminology though.
Here is an example of its usage if you are interested: https://github.com/stephane/libmodbus/blob/master/tests/unit-test-client.c
EDIT: Benefit of open source is easy confirmation. Observe in https://github.com/stephane/libmodbus/blob/master/src/modbus-tcp.c that the ctx->slave as set by modbus_set_slave() is set in the request packet.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With