amswitch Posted August 5, 2016 Share Posted August 5, 2016 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 More sharing options...
AzeoTech Posted August 6, 2016 Share Posted August 6, 2016 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 More sharing options...
amswitch Posted August 8, 2016 Author Share Posted August 8, 2016 Thanks for the reply. Under Sequences, I wrote the same script (replacing 'myLog' with 'log1'), but every data point is still being logged. Link to comment Share on other sites More sharing options...
AzeoTech Posted August 8, 2016 Share Posted August 8, 2016 Did you you run the sequence, or did you start the logging set directly? I've attached a sample that does exactly what I said and shows it working. Hopefully this will help you. You may need to change where the myLog logging set is logging to. logInterval.ctl Link to comment Share on other sites More sharing options...
amswitch Posted August 8, 2016 Author Share Posted August 8, 2016 OK, I got it now. I was logging the set directly instead of running the sequence. Thanks~ Link to comment Share on other sites More sharing options...
amswitch Posted August 9, 2016 Author Share Posted August 9, 2016 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 More sharing options...
AzeoTech Posted August 9, 2016 Share Posted August 9, 2016 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 More sharing options...
amswitch Posted August 10, 2016 Author Share Posted August 10, 2016 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 More sharing options...
AzeoTech Posted August 10, 2016 Share Posted August 10, 2016 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 More sharing options...
amswitch Posted August 10, 2016 Author Share Posted August 10, 2016 My bad, for the start button I actually have: UI(3,"start") beginseq(log3) And log3 is: while(1) wait(10) beginLogging(station3) wait(10) endLogging(station3) endwhile Link to comment Share on other sites More sharing options...
AzeoTech Posted August 10, 2016 Share Posted August 10, 2016 That's better, but I still don't know what UI(3,"start") does, so can't really address the Runtime error. Perhaps you can just post your full .ctl document? Link to comment Share on other sites More sharing options...
amswitch Posted August 12, 2016 Author Share Posted August 12, 2016 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 More sharing options...
AzeoTech Posted August 17, 2016 Share Posted August 17, 2016 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.