Problems with WaitUntil Sequence


tlemar

Recommended Posts

I am having problems with the sequence shown below:

if (SysTime()<23h) 
   WaitUntil(23h)
else
   WaitUntil(23h+3600)
endif

while (1)  
  beginseq(ReadChannels)
  ?"Exported Data - " + formatdatetime("%c",systime())
  beginlogging(midnightread) 
  WaitUntil(23h+86400) 
endwhile

When I compile, it shows that this sequence will loop more than 100 times. Based on the user guide, I was hoping that this code would read the channels and log them at 11:00 pm every night. How when stepping thru this sequence, it does not stop at the WaitUntil lines, it just runs thru them. Am I missing something?

Also, if I wanted to read at Midnight every night would I use 0h or 24h?

thanks

Tracy

Link to comment
Share on other sites

I find the user's guide as confusing as you probably do on this sample. Personally, I'd do it like this:

// find starting time
private nexttime = 23h
if (nexttime < systime())
   nexttime += 86400
endif
while(1)
   waituntil(nexttime)
   nexttime += 86400
   beginseq(ReadChannels)
   ?"Exported Data - " + formatdatetime("%c",systime())
   beginlogging(midnightread)
endwhile

If you want midnight, you want 0h. 24h doesn't exist and will give you some weird date.

Also, are you sure you want beginlogging()? I'm not sure what you are doing in ReadChannels, but if you just want to log a single line of data after the data has been taken, I think you want an export set.

Link to comment
Share on other sites

Thank you, that code make more sense.

As far as your comment regarding logging, what I am trying to do is read the channels at midnight, and then place the values in an SQL dbase. Based on your comments, it sounds like I would be better off exporting rather than logging. Is there a way to export the raw (unconverted) values also?

Also, is it possible to use INSERT or UPDATE statements in the db.QUERY command?

Link to comment
Share on other sites

Yeah, logging sets are designed for continuous running. They have to be running when the data is acquired. Export sets are designed to export data after its been acquired, though typically they are used to log a single line of data on demand. If you are handy with SQL (and it sounds like you are) you may want to just do your logging directly in script instead of using logging or export sets. The db.Query() command only supports SELECT, but db.Execute() supports all the rest and can be used to create and edit tables, add, insert and remove records, etc.

PS: check out some of the other posts for the QueryToClass() function if you are going to do a bunch of querying as well. Here's one: http://www.azeotech.com/board/index.php?&showtopic=3332 and also look in the Logging forum.

Link to comment
Share on other sites

Archived

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