Log Time Stamp


boliva

Recommended Posts

I've created multiple channels that get sampled once per second.  I have a log file that I would like to average 600 seconds and log that average.  I have a sequence that waits until an even 10-minute period (6:00, 6:10, 6:20, etc) to start the log so that everything stays on the same period, but the log samples seem to correlate to the actual time that DAQFactory started.  I've tried setting the timing of all of my channels to 0 then back to 1 in an attempt to reset this time, and also set the history of all channels to 0 then back to 1, but neither seem to force the logged time to begin at an even 10-minute interval, it always stays at 6:08 or whenever I start DAQFactory.  Is there a way to accomplish this?

Link to comment
Share on other sites

You should probably put the result of the average into a variables, then use an export set instead of a logging set to log the value of those variables.  Put the export set into snapshot mode.  Trigger the export set right after you calculate the average.

 

Logging sets really are designed for precise long term logging of live data.

Link to comment
Share on other sites

The ultimate goal is to take an average of each parameter being logged every 10 minutes and at the end of a 12 or 24hr period, email a single csv file containing all of the samples that were averaged.  At the end of the 12hr or 24hr period, it will rename the file and basically begin again.  Would this be best accomplished with an export set?  I want the long term logging, just want the time stamps to be at an even 10-minute period so all systems log the same from one machine to the next, regardless of when DAQFactory was started on the PC.

Link to comment
Share on other sites

Just note that there will be some drift in clocks between PC's over time.  You may want to use the Windows System Clock download on our Downloads page so that DAQFactory uses the system clock instead of the high precision clock.  Unless you need millisecond precision in your data, this is a better choice and will keep the clocks aligned (assuming Windows is setup to sync with an network time server).  Just watch out for DST.

Link to comment
Share on other sites

Just to make sure I'm heading down the correct path...

   1.  Create an array with the channel names to be sampled

   2.  Create a variable for each channel.  This will store the average value over the period determined.  This will be an array at the end of a 12-hour period

   3.  Every 10 minutes (period determined), take the average of each channel and append this average to the back of the variable just created in 2 as an array of strings, with a "," after each value.  The ", " will serve as the delimiter for the csv file when done, between values.  When doing this, only write to the channels whose names are actually in the array to be sampled.

   4.  At the end of each 12-hour or 24-hour period, write the variables to a .csv file then change the file name to begin a new one for the next period

 

Sounds right?

Link to comment
Share on other sites

No.  There is no reason to store the averages, and you don't want to wait 12 or 24 hours to write the data, otherwise if power goes out or the system is shut off, you would lose the data.  So, here's a quick sample.  I haven't checked it for syntax errors but it should get you close:

 

private chanList = {"firstChan", "secondChan", "thirdChan"}
private filePath = "c:\data\"
// wait until next 10 minute interval
waitUntil(ceil(systime() / 600) * 600) 
// we don't really want to log right away.  We want to give the system time to accumulate at least 10 minutes worth of data:
delay(1) 
while(1)
   // wait until next 10 minute interval
   waitUntil(ceil(systime() / 600) * 600) 
   try
      // save so averages are over the same block
      private theTime = systime() 
      // create a file name based on the date, not the time.  It will automatically create a new one every day:
      private handle = file.open(filePath + "myData_" + formatDateTime("%y%m%d", systime()) + ".csv", 0, 1, 1, 1)  
      // write just the seconds part of the time stamp.  Change the 0 to the number of decimals desired. Use FormatDateTime() instead if you want human readable format:
      private string out = format("%.0f", systime()) + ","   
      // now cycle through the channels:
      for (private i = 0, i < numrows(chanList), i++)
         private val = evaluate("mean(" + chanList[i] + "[theTime, theTime - 599.999])")
         out += format("%.3f", val) + ","  // display 3 decimals in data
      endfor
      // now remove trailing ,:
      out = left(out, getLength(out) - 1)
      // and write:
      file.write(handle, out)
      // and close file until next time:
      file.close(handle)
   catch()
      ? strLastError
   endcatch
endwhile
Link to comment
Share on other sites

Archived

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