← Back to team overview

modbus team mailing list archive

Re: Make libmodbus more usable

 

2009/6/23 Stratiyenko Roman <picoworm@xxxxxxxxx>

>   Dear modbus team!
>
> In my project I need to use your lib. But I am using it in real-time
> system.
>
> So I need to separate the Communication API from Message-generation
> functions.
>
> So, the code must be next:(simple version of slave)
>
> char *InBuf, *OutBuf;
> int InLength, OutLength;
> volatile bool MessageReceived, ResponceReady;
>
> void nonRT_Thread() {  // (non real-time thread. Communication only)
>      ... Initialize Modbus
>      for (;;) {
>          modbus_receive(...InBuf, &InLength);
>          ResponseReady=0; MessageReceived=1;
>          while (!ResponceReady) { // Wait response from RT thread
>                usleep(20000);
>          }
>          ResponceReady = 0;
>          modbus_send(..., OutBuf, OutLength);
>      }
> }



libmodbus doesn't poll but uses select() so the sleep is a bit strange.
modbus_receive blocks and cancels on Modbus timeout.

Have a look at the trunk because there is already a separation between the
communication and message generation functions (may be not perfect).

Regards,
Stephane

References