How To Add A Delay To A Buffer

This is a discussion on How To Add A Delay To A Buffer within the C++ Programming forums, part of the General Programming Boards category; Hey all, I have a question about adding a delay into a buffer that I use to communicate between to ...

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    7

    How To Add A Delay To A Buffer

    Hey all,

    I have a question about adding a delay into a buffer that I use to communicate between to serial ports on a Linux system.

    When serial port 1 receives data, it has to sent it to a buffer and this buffer has to sent the data further to the second serial port.

    Now I want to add a delay to the buffer output. So when the buffer gets data it has to keep it there for, lets say 500 miliseconds and then sent it to port two.

    Can someone give me an explanation about the things I have to do, to create this delay?

    Thanks for your support.

    Allart

  2. #2
    Registered User
    Join Date
    Jan 2003
    Posts
    311
    How hard is your requrement? My first choice would be select (check man page). That or a simple "spin lock" where you loop 5000 times then check the availibility of the port. These sorts of things are known as "real time" programming, it's much more art than science but real time and linux are your magic google words.

  3. #3
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

    <ctime> or sleep()

    Check your compiler's documentation. Your compiler should have a system-specific (non-portable, non-standard) function such as sleep() or delay()... maybe usleep(). This function will pause your program while telling the operating system that it's OK to go-away and do other stuff 'till the time delay is up.

    There are functions in the standard <ctime> header that would allow you to count elapsed time while waiting in a "do-nothing" loop for n milliseconds. However, the standard-language techniques are BAD in a multitasking system because the loop hogs the CPU.

    Since Linux is not a real-time operating system, you cannot get an exact 500mS delay. You can get a delay of at least 500mS. This is because the multitasking system is not going to suddenly halt another current "task" and jump-back to your program at the precise end of the delay.
    Last edited by DougDbug; 05-24-2005 at 03:41 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Print out a buffer
    By SwarfEye in forum C Programming
    Replies: 4
    Last Post: 09-08-2006, 10:32 AM
  2. writing a pack-style function, any advices?
    By isaac_s in forum C Programming
    Replies: 10
    Last Post: 07-08-2006, 09:09 PM
  3. delay between two readings from a buffer?
    By Hunsson in forum C Programming
    Replies: 2
    Last Post: 03-30-2004, 05:28 PM
  4. Add and delete functions
    By Ana Val sazi in forum C++ Programming
    Replies: 5
    Last Post: 06-18-2002, 10:59 PM
  5. Can somebody test this code please
    By andy bee in forum C Programming
    Replies: 6
    Last Post: 10-09-2001, 04:08 PM

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