how to set timer

This is a discussion on how to set timer within the C Programming forums, part of the General Programming Boards category; i need to set a timer to timeout if no data is received from the serial com port. I cant ...

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    1

    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

  2. #2
    Registered User Azuth's Avatar
    Join Date
    Feb 2002
    Posts
    236
    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.
    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, 01:23 AM
  2. The new FAQ
    By Hammer in forum A Brief History of Cprogramming.com
    Replies: 34
    Last Post: 08-30-2006, 11: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, 01:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21