Thread: how to set timer

  1. #1
    Registered User
    Join Date
    Feb 2003

    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?


  2. #2
    Registered User Azuth's Avatar
    Join Date
    Feb 2002
    #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.
    Demonographic rhinology is not the only possible outcome, but why take the chance

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SIGALRM and timer
    By nkhambal in forum C Programming
    Replies: 1
    Last Post: 06-30-2008, 12:23 AM
  2. The new FAQ
    By Hammer in forum A Brief History of
    Replies: 34
    Last Post: 08-30-2006, 10:05 AM
  3. C help for network animator
    By fastshadow in forum Tech Board
    Replies: 7
    Last Post: 03-17-2006, 03:44 AM
  4. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM