Callback support for libmodbus 2.0
In our work with the Modbus protocol we found it useful to utilize a library by Stephane Raimbault – libmodbus.
One of our recent projects, however, required one particular functionality which the library did not provide, so we decided to add it.
The addition enables a more event-driven approach to Modbus, utilizing callbacks to allow the user to perform commands rather than simply store values. This also enabled us to implement another way of storing bit values (which was used in one of our customer’s devices we had to interface with).
Callbacks that have to be hooked are:
uint8_t modbus_get_coil_status(void *data, uint16_t address); void modbus_set_coil_status(void *data, uint16_t address, uint8_t value); uint8_t modbus_get_input_status(void *data, uint16_t address); uint16_t modbus_get_input_register(void *data, uint16_t address); uint16_t modbus_get_holding_register(void *data, uint16_t address); void modbus_set_holding_register(void *data, uint16_t address, uint16_t value);