in reply to Serial Port timing and write blocking?

Keep in mind that unless you are running on a hard real-time system, there are no guarantees on usleep. All it guarantees is that it will wait at least as long as the the argument. You might look into Time::Clock, which says it guarantees time to within nanoseconds.
  • Comment on Re: Serial Port timing and write blocking?

Replies are listed 'Best First'.
Re^2: Serial Port timing and write blocking?
by TGI (Parson) on Aug 05, 2008 at 01:02 UTC

    Your point about hard real-time systems is very good.

    Time::Clock uses Time::HiRes. It doesn't really buy anything. Especially since it doesn't offer a sleep function. Time::HiRes also offers a nanosecond sleep function.

    If you have access to a high-precision timer, you can use clock_nanosleep to control your timing based on the high precision timer.

    It's also worth checking the return value of your sleep-type calls. They tell what the actual sleep time was. That way, if your sleep was interrupted by a signal, or if your sleep ran long for some reason, you will know, and can take appropriate action.


    TGI says moo