I have used the libmodbus to build a project to connect to my device by modbus-tcp. The project run. But Unit ID is wrong. My ID slave is 0xFE. However it is fixed as 0xFF whenever I send a modbus-tcp package. I had tried to change it by function modbus_set_slave
but it did not work.
How can I change it?
Libmodbus: https://github.com/stephane/libmodbus
"modbus_read_registers(modbus_t *ctx, int addr, int nb, uint16_t *dest);"
It's clear that I cannot put Unit ID in above function to read value a register. enter image description here
Actually function modbus_set_slave
is the answer. The reason why it did not work is that I made a mistake with the link. Moreover, I can chang the ID unit by fixing it in other function because the library is available to modify.