Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

libmodbus Unit ID altering

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?

like image 546
Cornel Verster Avatar asked Mar 22 '26 04:03

Cornel Verster


1 Answers

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.

like image 82
Jarra McIntyre Avatar answered Mar 25 '26 02:03

Jarra McIntyre