Using sleep (or usleep from Time::HiRes) is how I've done it in the past, but the problem is accumulating time inaccuracy do to delays in processing.
For a bit more context, I'm taking measurements from electronic test equipment using the GPIB bus. I want to take those readings, say, every 10 seconds. The time it takes to tell the instrument to send a reading, for the instrument to process that request, and then return the result, is somewhat variable. So it's very hard to calibrate the sleep time to keep accuracy.
What I want to do is trigger the measurement cycle every X seconds regardless of how long (less than X, obviously) the measurement process takes.
In one previous iteration, I used HiRes gettime calls before and after the read/write cycle to determine how long the processing took, and used that to adjust the sleep time, but that seemed an awfully awkward way to go. I was hoping that a recurring alarm (which the HiRes setItimer function allows) would be a more elegant way to go.
Thanks!
Hope this helps clarify.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.