Best Way To Trigger A Sequence For Logging Every 5 Minutes


gillecaluimi

Recommended Posts

Just create an infinite loop with delay():

 

while(1)

   // do the mysql write, or call the sequence

   delay(300)

endwhile

 

If you want it on the 5 minute mark, use a little math:

 

private nextTime = floor(systime() / 300) * 300 + 300

while(1)

   waitUntil(nextTime)

   // do the mysql stuff

   nextTime += 300

endwhile

 

This is also a bit more precise in its timing.

Link to comment
Share on other sites

that's what I'd finally found in the user pdf but wasn't sure if it chewed up a bunch of cpu cycles constantly checking for nextTime?  I'm used to programming event driven software and thought there might  be a timer where you could set the interval and trigger a sequence.

Link to comment
Share on other sites

Its not constantly checking nexttime.  waitUntil() handles all the cpu management for you.  Of course this would chew up your cpu:

 

while(systime() < nexttime)

endwhile

 

but waituntil() along with the other time functions in DAQFactory are designed not to simply spin like that.  In fact, I'd imagine most of the event driven software you've used is doing it in software anyway, and is not truly event driven (i.e. interrupt driven).  DAQFactory is just much more linear in its thinking, which makes it much easier for you as the developer.  We use events internally to avoid using the cpu, but you never have to see it.  You can just call waituntil() and know that we'll wake up at the right moment using the minimal amount of cpu possible.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.