← Back to team overview

modbus team mailing list archive

Re: New API for libmodbus 2.2.0

 

Hello,

I'm using libmodbus for about 2.5 months in prototype of industrial controller and got some API suggestions, maybe you'll find them useful.

(1). Add possibility to use functions to get registers values in addition to arrays, i.e. add following typedefs in modbus.h:
----
typedef uint8_t (*get_status_function_ptr)(uint16_t);
typedef uint16_t (*get_register_function_ptr)(uint16_t);
typedef int (*set_status_function_ptr)(uint16_t, uint8_t);
typedef int (*set_register_function_ptr)(uint16_t, uint16_t);
----

and members in modbus_mapping_t in modbus.h:
----
typedef struct {
   ...
   get_status_function_ptr get_coil_status;
   get_status_function_ptr get_input_status;
   get_register_function_ptr get_input_register;
   get_register_function_ptr get_holding_register;
   set_status_function_ptr set_coil_status;
   set_register_function_ptr set_holding_register;
} modbus_mapping_t;
----
In query managing functions should be test -- if, for example, tab_coil_status pointer is NULL, then use get_coil_status function and vice versa. I suggest it because in my project variables are 4 byte long (long and float) and duplicating them in array only for using libmodbus is strange, but with functions I can implement needed logic.

(2) Add ability to use non-blocking sockets in addition to traditional blocking. I think it will be useful, because I use modbus in following scheme: modbus listen thread tests, if it should listen, then call modbus_slave_accept_tcp (and blocks here until connection comes), then again test, if thread should listen, and process messages (again blocking at each receive).

So, if I ask thread not to listen, when it is blocked at accept, it will get it only when it will accept something, and it's absolutely not suitably for me, because connection may never come. Of course it's possible to use pthread_cancel, but it's behavior is not so controllable like when using non-blocking functions.

I'm ready to implement this features, if you'll find them useful. It's only needed to discuss, how to integrate it in libmodbus in the best way.

Thanks.

--
Best Regards, Dmitry Vinokurov <d.vinokuroff@xxxxxxxxx>


Hello Modbus contributors,

I intend to release a new version of libmodbus, 2.2.0.
The API has changed since 2.0.X series and I'm looking for feedback >about the changes:
http://bazaar.launchpad.net/~sra/libmodbus/trunk/annotate/head%3A/MIGRATION <http://bazaar.launchpad.net/%7Esra/libmodbus/trunk/annotate/head%3A/MIGRATION>



Ciao,
Stephane