Logging on the half hour


AzeoTech

Recommended Posts

From the direct emails:

I am trying to get a file to log every half hour (1800s)

I have a Logging component called TEST.

The file needs to log on the exact half hour so 15:00, 15:30. 16:00, 16:30 etc.

I have tried the below piece of code which does nothing.

while (1)
   // set the logging file name to "My_File" plus the date/time
   Logging.Test.strFileName = FormatDateTime("My_File_%y%m%d.csv",SysTime())  
   // wait until next half hour
   waituntil(floor(SysTime() / 1800) * 1800 + 1800)
endwhile

the below piece of code

while (1)
 // set the logging file name to "My_File" plus the date/time
 Logging.Test.strFileName = FormatDateTime("My_File_%y%m%d.csv",SysTime())  
 // wait until next hour
 waituntil(floor(SysTime() / 3600) * 3600 + 3600)
endwhile

Works and logs the file every hour on the hour

And the below piece of code works and logs the file evey hour on the half hour (15:30, 16:30 etc)

while (1)
 // set the logging file name to "My_File" plus the date/time
 Logging.Test.strFileName = FormatDateTime("My_File_%y%m%d.csv",SysTime())  
// wait until next hour
 waituntil(floor(SysTime() / 3600) * 3600 + 3600)
 // wait until next half hour
 waituntil(floor(SysTime() / 3600) * 3600 + 1800)
endwhile

Am I on the right tracks or miles off?

I

Link to comment
Share on other sites

I find it easier not to use waituntil in this way. Instead, calculated the next logging time once, and increment it by 30 minutes each time:

private nexttime = floor(systime()/1800) * 1800 + 1800  // calc next half hour point
while (1)
   waituntil(nexttime)
   .. do whatever you want at the half hour
   nexttime += 1800
endwhile

Also, you don't have anything in your code to actually do the log. It appears all you do is change the file name. But with only %y%m%d in the format specifier, you are only changing the year, month and day, so even though you are trying to do it 48 times in a day, the value only changes once a day. Did you perhaps want a beginexport() in there?

Link to comment
Share on other sites

Archived

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