Hello.
Just learning how the libmodbus works. I am using libmodbus v3.1.7 tag from git repo.
I wrote a very simple test, included as reference, where all error management has been removed for clarity:
ctx = modbus_new_rtu("/dev/ttyUSB0", 115200, 'N', 8, 1);
modbus_set_slave(ctx, 0xF0);
modbus_rtu_set_serial_mode(ctx, MODBUS_RTU_RS232);
modbus_connect(ctx);
mb_mapping = modbus_mapping_new(MODBUS_MAX_READ_BITS, 0, MODBUS_MAX_READ_REGISTERS, 0);
while(1) {
modbus_receive(ctx, query);
print_query(query, MODBUS_RTU_MAX_ADU_LENGTH);
}
The purpose is reading every message for a given slave and printing it on the screen.
However, the test is printing messages with a destination address different from 0xF0 (as you can see, the slave address set).
Documentation, in file doc/libmodbus.txt, explains this:
Many Modbus devices can be connected together on the same physical link so
before sending a message, you must set the slave (receiver) with
linkmb:modbus_set_slave[3]. If you're running a slave, its slave number will be
used to filter received messages.
I was expecting the filter will work, filtering messages received with address different from 0xF0. Why is not working as expected?
Many thanks in advance!