Le 07/02/2014 08:14, Uğur Onursal a écrit :
> I am also curious about how to draw values from mapping registers to a
> usual variable.
>
Hi !
Your questions seems more general programming related than libmodbus
specific.
The modbus_mapping structure is the following :
typedef struct {
int nb_bits;
int nb_input_bits;
int nb_input_registers;
int nb_registers;
uint8_t *tab_bits;
uint8_t *tab_input_bits;
uint16_t *tab_input_registers;
uint16_t *tab_registers;
} modbus_mapping_t;
It is a public struct (imho it should be made opaque, but that’s a
different concern), so you can just directly acces the data using
mb_mapping->tab_registers[register_number] (note that it will fail if
register_number is greater than nb_registers), either for reading or
writing it.
If your concern is to be notified (ie, do a specific treatment) when a
value changes (via master command, for example), there is currently no
way in standard libmodbus to do that. There are, however, some forks
available on github that allows this :
https://github.com/forslund/libmodbus/tree/custom_requests_handlers for
a complete solution
https://github.com/bomm/libmodbus/tree/callback1 for a (maybe) simpler one
But i would recommend that you solve any other issues you have before
looking into these options. You can do active polling (ie, update the
file with modbus_mapping_t content every tenth seconds for example) as a
first time approach.
Regards,
Julien