3

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?

Cornel Verster
  • 1,664
  • 3
  • 27
  • 55

1 Answers1

3

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.

Jarra McIntyre
  • 1,265
  • 8
  • 13