LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I use a single STOP button to abort all my loops in an event structure.

Solved!
Go to solution

Hello, I am designing a testbench in LabVIEW and am using DQMH framework to make that. In my testing module, I have a test case where I have to use multiple nested loops to program the logic and I am trying to integrate an abort test button, which will stop all the current loops and exit the module. But I am running into problems where I cannot stop everything using just one button. I appreciate any assistance or suggestions that I can make to my code. I am attaching a dummy vi that is similar to the code structure that I am working with, including explanations of why I am using each loop structure.

0 Kudos
Message 1 of 8
(407 Views)
Solution
Accepted by topic author mp6598

There are many ways to do this, but they are all highly dependent on what the loops are doing and whether or not you are controlling hardware that could be dangerous to the user.

 

Here is a good KB article on parallel loop control that can be applied to inner loops too:  Stopping Parallel While Loops in LabVIEW with One Stop Button - NI

Also try a search for " labview how to stop inner loops? " for more info.

 

In your example code you run a for loop to extract data from a table.  In that case I would just extract the data in a separate loop first, then pass it into your state machine as an array.  Don't forget, you can also add a conditional terminal to a for loop as well.

 

In the simplest case, just using an E-STOP boolean passed around with local variables an OR'd with your stop terminals will work.  It's generally better to use notifiers, queues, etc., but this will work too.

NIquist_0-1742481777853.png

Honestly though, the best solution is to NOT design your code with many nested structures.  Especially if they run slowly.  Passing tasks to other external loops with a Producer-Consumer architecture is preferred.  The DQMH should be designed to help with this.  Don't quote on that, though.  I've looked at it, but never really used it 

LabVIEW Pro Dev & Measurement Studio Pro (VS Pro) 2019
0 Kudos
Message 2 of 8
(360 Views)

Place the Stop in the innermost loop and wire it out to the outer ones, then once stopped all others will also stop at the same time.

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 3 of 8
(354 Views)

The correct way is not to use a deep stack of loops. Once you implement this as a proper state machine, you can use the top-level loop for all the "spinning" and just implement proper allowed transition between states (e.g.: only if it executed N times, simulating an inner FOR loop) and so on. This also means that for every iteration, you have a chance to stop IF that is a permitted operation after that step.

 

 

Message 4 of 8
(345 Views)

@altenbach wrote:

The correct way is not to use a deep stack of loops. Once you implement this as a proper state machine, you can use the top-level loop for all the "spinning" and just implement proper allowed transition between states (e.g.: only if it executed N times, simulating an inner FOR loop) and so on. This also means that for every iteration, you have a chance to stop IF that is a permitted operation after that step.

 

 



Thanks for the response. If possible can you explain further what you mean by top-level loop for all the spinning. I ended up using notifiers as a way to stop everything but I think this was just a functional solution. I wanted to use fewer loops but I couldnt figure out a way to program my test logic and as NIquist said, I can maybe run my for loop separately to extract data from a table and pass it as an array to my main main loop but otherwise I could not think of something. 

0 Kudos
Message 5 of 8
(299 Views)

@NIquist wrote:

There are many ways to do this, but they are all highly dependent on what the loops are doing and whether or not you are controlling hardware that could be dangerous to the user.

 

Here is a good KB article on parallel loop control that can be applied to inner loops too:  Stopping Parallel While Loops in LabVIEW with One Stop Button - NI

Also try a search for " labview how to stop inner loops? " for more info.

 

In your example code you run a for loop to extract data from a table.  In that case I would just extract the data in a separate loop first, then pass it into your state machine as an array.  Don't forget, you can also add a conditional terminal to a for loop as well.

 

In the simplest case, just using an E-STOP boolean passed around with local variables an OR'd with your stop terminals will work.  It's generally better to use notifiers, queues, etc., but this will work too.

NIquist_0-1742481777853.png

Honestly though, the best solution is to NOT design your code with many nested structures.  Especially if they run slowly.  Passing tasks to other external loops with a Producer-Consumer architecture is preferred.  The DQMH should be designed to help with this.  Don't quote on that, though.  I've looked at it, but never really used it 



Thank for a detailed explanation.I tried using an E-stop button with local variables to stop the loops but I always got an error saying that "Boolean latch action is incompatible", so I couldnt figure it out. Ultimately, I ended up using notifiers to pass a boolean value which I press my stop button to all the loops. I agree with your assessment that maybe I could use a separate loop for my 'For loop' to extract data from a table making the code a bit leaner but I could not figure out how to avoid using nested loops for my test logic. Still, thanks for your solution.

0 Kudos
Message 6 of 8
(296 Views)

I meant a simple state machine. Once you attach some real code (not some pile of meaningless code), I can give more specific advice.

 

Not much of your attachment makes sense. Why do you need a FOR loop to extract data from a table?

 

 

Also note that wiring a local variable to its own control as seen in one of the suggestions is pure Rube Goldberg and completely pointless.

altenbach_1-1742591046723.png

 

 

 

0 Kudos
Message 7 of 8
(238 Views)

@mp6598 wrote:
Thanks for the response. If possible can you explain further what you mean by top-level loop for all the spinning. I ended up using notifiers as a way to stop everything but I think this was just a functional solution. I wanted to use fewer loops but I couldnt figure out a way to program my test logic and as NIquist said, I can maybe run my for loop separately to extract data from a table and pass it as an array to my main main loop but otherwise I could not think of something. 

OK, I made a very simple example that simulates inner loops with the outer loop.

 

  1. A user controlled state (Idle: wait for button)
  2. A state that runs once when no longer in idle state (Generate: Generate value, then go to next state)
  3. A fake inner FOR loop (Process A: repeat N times, then go to next)
  4. A fake inner while loop (Process B: repeat state until condition is true, then go back to idle)

 

altenbach_0-1742594045324.png

 

0 Kudos
Message 8 of 8
(221 Views)