Interval Logging - logging data every 20 seconds


amswitch

Recommended Posts

Hi, I'm trying to write a sequence where data is logged at the 10 second mark, stops at 20 seconds, and then starts logging again at 30 seconds.  So at 10sec, 30sec, 50sec, 70sec, etc. data is logged for 10 seconds.  Any suggestions on how I could do this?

Thanks!

 

Link to comment
Share on other sites

Depends on how precise you want the 10 second mark.  At its simplest, you could create a logging set and the start and stop the logging set inside a sequence.  The script would look something like this:

while(1)
   wait(10)
   beginLogging(myLog)
   wait(10)
   endlogging(myLog)
endwhile

Note that I use wait() instead of delay() so our loop doesn't drift.  DAQFactory may warn you about using wait(), but in this case its appropriate.  The problem with this method is that there may be up to 1 second in lag from the logging set itself.  Try this and see if it does what you want, then post again here if not and I can delve into a more precise, but more complicated way.

 

Link to comment
Share on other sites

Hi,  I'm now trying to start the sequence automatically when I press the 'Start' button I created.  I tried adding the same script under the 'Start' button's Action > Quick Sequence as follows:

  UI(3,"start")
while(1)
   wait(10)
   beginLogging(station3)
   wait(10)
   endLogging(station3)
endwhile

But when I press start, the program freezes and I have to close it without saving.  I don't think selecting 'Auto-Start' within the Sequence section itself will help, since I'm trying to set up my program to have two different voltage reading stations, each having their own separate 'Start' buttons.  I want to set up the program so that when I hit 'Start' on an individual station, the voltage will be logged according to the sequence automatically.  Any suggestions?

Thanks~

Link to comment
Share on other sites

Quick Sequence actions as well as script you type in the command / alert window run in the main application thread.  This is the same thread that handles the user interface.  This is required as having them run in the background would make the user interface you create not work the way you want.  There would be lags.  Anyhow, what this means is that the script has to be fast and return so that Windows / DAQFactory can still draw the user interface, process mouse clicks, etc.  When you put script there that is slow, or in your case, is an infinite loop and never returns, then DAQFactory never redraws resulting it appearing hung.  In fact, its not hung, just the user interface thread is busy running your script instead of redrawing the screen.  Acquisition is still running, as are any background sequences or logging sets, etc.  

So, when you want to run something like your sequence script, which really wants to run in the background as the user interface continues to function, you need to start the sequence.  You can start it from a button two ways:

1) use the start/stop sequence action: the problem with this is that a second click stops the sequence.  Sometimes this is what you want

2) to only have the button start the sequence (perhaps with another to stop), use a quick sequence action for the button and put something like:

beginseq(myseq)

where myseq is the name of the sequence to start in a background thread.  Note that unlike most functions, myseq should not be in quotes.

Use:

endseq(myseq)

to stop the sequence.

Link to comment
Share on other sites

So, I have a start and a stop button.  For the start button I have:

  UI(3,"start")
while(1)
   wait(10)
   beginLogging(station3)
   wait(10)
   endLogging(station3)
endwhile

For the stop button I have the following:

UI(3,"stop")
endseq(log3)
endLogging(station3)

I found the endseq line wasn't enough; if the sequence was ended before endLogging was read in the loop, logging would still continue.  Therefore, I added the endLogging line again for the stop button.  Sometimes the stop button works fine, other times I get an error message saying:

"Runtine Error!  This application has requested the Runtime to terminate it in an unusual way."

I'm not sure what to do about this.

 

Link to comment
Share on other sites

As I said, you can't put code that runs slow, which includes a while(1) in the actual button action.  It will hang the UI.  I don't know what UI(3,"start") does so can't address that.  It might be the Runtime error issue.  Really it should probably be at the top of your log3 sequence.  And the while(1) block needs to be replaced with the beginseq(log3)

Link to comment
Share on other sites

I can't post the entire .ctl file since it's not all my code.  I think the error might be a result of the endLogging line being read twice, depending on the timing of the while loop.  

I'm modifying my code under the STOP button to first endseq, but if data is still being logged, the code reads endLogging.  I'm not sure if Logging(station3) is correct:

UI(3,"stop")
endseq(log3)
if(Logging(station3) != NULL)
   endLogging(station3)
endif
 

 

Link to comment
Share on other sites

Don't post it then, just email it to us so no one else can see it.

The if(logging(station3) != null) makes no sense unless logging() is a function you created, and in that case you probably have a name collision in the global namespace because "logging" is a reserved word used by DAQFactory.  What you want I believe is:

if (logging.myLog.Running)

Link to comment
Share on other sites

Archived

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