03-20-2025 07:20 AM
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.
Solved! Go to Solution.
03-20-2025 09:50 AM
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.
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
03-20-2025 10:01 AM
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.
03-20-2025 10:28 AM
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.
03-21-2025 04:14 AM - edited 03-21-2025 04:24 AM
@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.
03-21-2025 04:21 AM - edited 03-21-2025 04:25 AM
@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.
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.
03-21-2025 04:04 PM - edited 03-21-2025 04:18 PM
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.
03-21-2025 04:54 PM - edited 03-21-2025 04:55 PM
@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.