Modbus_Receive Timeout

652 views
Skip to first unread message

Joe Wilcoxson

unread,
May 10, 2013, 8:59:40 AM5/10/13
to libm...@googlegroups.com
I have a implementation of libmodbus acting as an RTU Server, the main loop looks like this:

while(runServer) {

uint8_t query[MODBUS_RTU_MAX_ADU_LENGTH];


rc = modbus_receive(mb, query);


if (rc != -1) {


modbus_reply(mb, query, rc, mm);

}

}


I use the runServer boolean to control when it needs to run, the only issue I am having is that when there is no client polling this server, the code stalls at modbus_receive(), therefore not checking while(runServer) and exiting the loop if needed. How could I put some sort of timeout on modbus_receive() so that if it doesn't get a query for a certain amount of time to go ahead and process the loop again and recheck while(runServer)?

Stéphane Raimbault

unread,
May 10, 2013, 9:03:47 AM5/10/13
to libm...@googlegroups.com
Hi Joe,

To do this you need to use select() syscall (on POSIX systems), you'll find an exemple in tests/bandwith-server-many-up.c


2013/5/10 Joe Wilcoxson <joe.wi...@gmail.com>

--
Vous recevez ce message, car vous êtes abonné au groupe Google Groupes libmodbus.
Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le concernant, envoyez un e-mail à l'adresse libmodbus+...@googlegroups.com.
Pour plus d'options, visitez le site https://groups.google.com/groups/opt_out .
 
 

Joe Wilcoxson

unread,
May 10, 2013, 9:42:06 AM5/10/13
to libm...@googlegroups.com
Stephane,
Thank you for the response, but after looking at the example and looking up select(), I'm still not exactly sure I understand what to do. Would you mind elaborating on exactly what select() is doing in this case?

Thank you 

Stéphane Raimbault

unread,
May 10, 2013, 11:40:57 AM5/10/13
to libm...@googlegroups.com
Joe,

I recommend you to read the select() documentation because it's not under the scope of libmodbus project (and it's not an easy topic).


2013/5/10 Joe Wilcoxson <joe.wi...@gmail.com>

Bill Smith

unread,
Oct 1, 2015, 5:10:23 PM10/1/15
to libmodbus
Stephane,
By what you wrote, am I to understand that the unit-test-server and client applications can not run as they are out-of-the-box for RTU without the same modification?

Thanks in advance for a reply,
Bill
Reply all
Reply to author
Forward
0 new messages