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.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to stop a loop while in wait

Hi all, I have a VI that basically automates a temperature ramp. once the Ramp Temp button is pushed the VI pull two rows of data from a .csv file (Setpoint and duration) to create a temperature ramp. All seems to work find but in the case that I would like to disrupt the ramp and go back into manual mode, I can't stop the VI while it's holding its wait time. Is there a simple way besides aborting the whole VI since this is a small part of bigger VI? Thanks in advance!  

0 Kudos
Message 1 of 11
(4,407 Views)

Hi Head,

 

the usual answer is: avoid long-running wait function calls!

 

When you want to wait for (lets say) 10s you can also wait 20 times for 0.5s…

 

Btw. your inner loop could by simplified to:

check.png

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 11
(4,403 Views)

Thanks Gerd that was a quick response! Yeah, I came to that conclusion. Your loop still will not work since you have the long wait and the3 conditional terminal will only execute after the delay. I'm thinking to just put a constant on the wait at 500 and double the time and put it to the N count terminal of the for loop. At least it should be able to pick up a stop command every 500ms.  On another note, your simplified version causes the output of the index array to change from an element to a subarray. This would be an issue for the input of the N count and next to be converted.

0 Kudos
Message 3 of 11
(4,319 Views)

I don't see any subarrays in Gerd's VI snippet.

 

All he did was take what you had and simplified it.  He only told you how to improve upon it.  He didn't code up his suggests for shorter waits and repeat reading of the stop button and more frequent intervals.

0 Kudos
Message 4 of 11
(4,311 Views)

I always do timer loops like this:

qCapture.PNG

Yes, there is a little more going on in here than waiting but in a nutshell the last time the loop exited (timestamp) is used in the data collection state and using a shift register fed back to the timer loop as the start time.

 

The scan interval (wait time) is added to the start time and the current time is subtracted until is is equal or less than 0

 

As you can see if the Stop button is pressed the timer loop will immediately (10mS at the most) exit.

========================
=== Engineer Ambiguously ===
========================
Message 5 of 11
(4,307 Views)

(On a side note, if you would use a timed loop, you can finish the waiting loop using this tool.)

Message 6 of 11
(4,287 Views)

I was looking into this and running into an issue with it (my lack of experience with it). I going to hit up Gerd's idea with a for loop x amount of time with a smaller wait delay so I can stop it. When I have more time, interested for sure into the timed sequence and the stop option. Thanks!

0 Kudos
Message 7 of 11
(4,262 Views)

@RTSLVU wrote:

I always do timer loops like this:

qCapture.PNG

Yes, there is a little more going on in here than waiting but in a nutshell the last time the loop exited (timestamp) is used in the data collection state and using a shift register fed back to the timer loop as the start time.

 

The scan interval (wait time) is added to the start time and the current time is subtracted until is is equal or less than 0

 

As you can see if the Stop button is pressed the timer loop will immediately (10mS at the most) exit.


Creative, nice!

0 Kudos
Message 8 of 11
(4,260 Views)

@RTSLVU wrote:

 

As you can see if the Stop button is pressed the timer loop will immediately (10mS at the most) exit.


 

Technically, it is 20mS at most. Because you didn't enforce data flow, the stop button control could be read (as FALSE) at the beginning of the loop. If you then press Stop immediately after the read but before the Wait starts, it would not be TRUE until after the next iteration of the loop.

 

For your example, a 20mS vs. a 10mS delay is still negligible. But it could make a big difference if the wait time was longer (multiple seconds). I got burned a few times when I first started programming and didn't quite understand all the nuances of dataflow. There are times I will use a Flat Sequence to force reading the Stop button value after the wait competes so that the loop exits at the proper time.

 

NOTE: I hate using Sequences. Is there a better way?

 

Stop after wait.JPG

 

0 Kudos
Message 9 of 11
(4,244 Views)

@jamiva wrote:

Technically, it is 20mS at most. Because you didn't enforce data flow, the stop button control could be read (as FALSE) at the beginning of the loop. If you then press Stop immediately after the read but before the Wait starts, it would not be TRUE until after the next iteration of the loop.

 

 


You are technically correct, and that's the best kind of correct! 😛

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 10 of 11
(4,239 Views)