-
how to set timer
i need to set a timer to timeout if no data is received from the serial com port.
I cant use sleep() as data may come in anytime and need to be processed immediately. sleep() will halt the program for that time.
How do i set an timer alarm to indicate timeout? Or is there any articles or ways that can help to solve the problem?
Thanks
Marianne
-
Code:
#include <time.h>
int main ( void )
{
clock_t strt_tmr;
strt_tmr = clock();
{ // Begin loop for reading data from serial port
// Code to scan from serial port goes here.
if ( clock() > (strt_tmr+10000) ) // check for timeout (10 seconds)
//set a flag here to exit loop with timeout error
}// End of code for scanning from serial port
return 0;
}
It's ugly, and it may not work (I can't compile anything where I am). Perhaps if you hold your tongue just right, you'll see what I was trying to aim for.