Just learning how the libmodbus works. I am using libmodbus v3.1.7 tag from git repository.
Wrote a very simple test, included as reference (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 of this test is reading every message for a given slave address (0xF0) and printing it on the screen. Function "print_query" prints all bytes of the message received on the stdout.
But this test is printing messages with a destination address different from 0xF0 (as you can see, the slave address set). File doc/libmodbus.txt in documentation explains:
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 should be applied in "modbus_receive" function, filtering messages received with an address different from 0xF0. But this doesn't happen. Some messages for different destination addresses are also received (and printed).
Is this simply not working as expected? Or maybe I am misunderstanding the documentation?
Many thanks in advance!