From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
03-16-2011 11:34 PM
Hello guys,
I have a While Loop contaning some jobs. One of them is delay for 10 seconds. When I push the stop button, the loop doesn't stop immediately. Instead, it will stop after a few seconds (may be, waiting the other jobs is done).
What can I do if I want to stop the loop immediately after I press the stop button?
Thank's for sharing..
Solved! Go to Solution.
03-16-2011 11:49 PM
hi
the loop will stop after the Stop button is read in the cycle, so, because you have a wait funtion of 10 sec, sometimes you may need to wait 10 seconds before stop. What you need to do is :
make a shift register, initialize with actual time (Now in the time palette)
put a wait for 250 msec or so (make sure you wire the error cluster)
compare the actual value of time with the one stored in the shift register (if samller than 10 sec do nothing, otherwise make what do you need to do AND change the time value of the shift register...)
in this case, the maximum wait time will be 250 milliseconds
(of course there are other ways : see the Time functions), but this one is a simple one
N
03-16-2011 11:56 PM
Hello Yoppy,
I am not sure if I have understood your problem completely, but below is one of the method that I use to stop the while loop immediately (Some ms delay will be there for sure).
Let me know if the attachment helps.
There are many ways to do it and you may get better solutions than this one on this community.
03-17-2011 12:20 AM
as a simple solution use the "Elapsed time" in the timing pallete.
Wire the "Reset" input with your Stop button and it will work for you as shown
03-17-2011 12:20 PM - edited 03-17-2011 12:21 PM
Hi yoppy, this is Paul with Applications Engineering at NI.
What others have said about the stop button is true because of the way LabVIEW handles data flow.
The best way to ensure stoppage of your program is to use an event structure, which may be a bit much for your simple program, but still check out these tutorials:
http://zone.ni.com/reference/en-XX/help/371361G-01/glang/event_structure/
http://zone.ni.com/devzone/cda/tut/p/id/12293
Also, unrelated to this, I see you are not handling errors properly here. By placing the error handler within your while loop, you will create a loop of errors that can cause LabVIEW to hang. I didn't full recreate your code, but it should look something more like this:
In this code, an error will stop the while loop via the unbundle function, and then will handle the error outside of the while loop.
For more info, check out: http://www.ni.com/gettingstarted/labviewbasics/handlingerrors.htm
03-22-2011 09:47 PM
Thank you for all your solutions guys. I feel that the solution from Krunal Patel suits my purpose the most. Still I have one question. Please see attachment below. Based on dataflow concept, I think that the duration for each one loop would be 6 seconds.
I think the process goes like this. The While Loop will loop until 5 seconds. Then, the case structure becomes TRUE and executes codes inside. These codes execution will take about 1,... seconds (write VISA -> delay 1 second -> read VISA). It is one cycle. After that, the loop re-iterates. So, each one loop will take 5 + 1 = 6 seconds.
But when run this code, I get different result. The duration for one loop is 5 seconds. It seems that when the TRUE Case sturucture is executing, the Get Date/Time is also executing simultaneously.
What I know about dataflow concept is that the TRUE Case structure should be done first. After that,the loop can re-iterates.
03-22-2011 10:15 PM
Your first time through, you probably get 6 seconds, but every time after that will be 5.
When you hit your 5 seconds mark, that time from the Get Date/Time which gets read at the beginning of your loop is placed into the shift register. Then your True case runs and takes a second. At the beginning of your next loop iteration, you take the time stamp again, but 1 second has already passed compared to the time stamp in the shift register because thats how long the previous loop iteration took when you ran the True case.
03-22-2011 10:39 PM
Yes. Thank you Ravens. Why do I never think about that.. It takes 5 seconds even for the very first iteration. It is the time stamp (TIME has not ever stopped since the beginning of TIME ) that makes the While loop seems to never wait for the TRUE Case. Many many thanks.
08-09-2016 08:12 AM
I think you could also use a STOP vi from the application control palette.
i used to put this vi on every single while loop and it worked just fine.
i'm not sure if its the ideal thing to do but it's done the job.
08-09-2016 08:45 AM
It's FAR from the ideal thing. If you want a graceful shutdown STAY AWAY FROM THE STOP.VI. Using the stop.vi is like using the abort button. It will stop LabVIEW in its tracks. Any references you have opened will remain open. Any equipment that you are using will be in an unknown state.
If you want to eject the warp core, then the stop.vi is for you. If you're interested in shutting down in an orderly fashion, then use one of the above methods.