LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Stop multiple parallel loops - error & stop button condition

Solved!
Go to solution

I have multiple loops running in parallel and want them all to stop looping based on whether either of the two conditions are true:

 

  • Any of the loops has an error
  • A stop button is pressed

 

Right now I'm doing this by using a master loop that checks if any of the loops have an error, or if the stop button is pressed.

master loop.jpg                                                  status 1.jpg

The problem I'm having is that I'm making references between the loops using T/F status lights. These light up if any of the loops stop. This means that at the end of a test all of the lights are lit up, and before the program is run again every light must be unchecked. This isn't user friendly and as my program grows I don't want to have to uncheck 20 lights before each test.

 

front panel.jpg

 

Is there a way to make the lights reset at the beginning of each test, or is there a better way to reference the status of each loop?

0 Kudos
Message 1 of 9
(7,436 Views)

Create a functional global VI called AllStop.  Write to it in any loop where an error condition is True or when the Stop button is pressed. Read it in every loop and use its output to stop the loops.  Initialize it to false when the program starts.

 

Lynn

0 Kudos
Message 2 of 9
(7,433 Views)

Create a functional global VI called AllStop.  Write a True to it in any loop where the error condition requires stopping or when the Stop button is pressed. Read it in each loop and connect its output to the stop terminal in the loop.  Initialize it to False when the program starts.

 

Lynn

0 Kudos
Message 3 of 9
(7,432 Views)
Solution
Accepted by topic author LittleOwl

An alternative is to use a Notifier.

 

 

Set up a notifier with the data type being a boolean.

 

Wire the stop terminal of both loops to the output of a Wait For Notification (dont forget to set a timeout).

 

If an error occurs, or stop is pressed then send a notification.

 

Clicking Stop will stop both loops. Or an error in either loop will stop both.

 

This isnt any more complicated than an FG I think.

 

AllStop.JPG

 

 

Message 4 of 9
(7,428 Views)

Or, to keep it your way now, you could use a 'Reinitialize To Default Values' invoke node at the beginning of your program.

 

This way, everytime you restart your program, the lights will be off (assuming that their default value is off).

0 Kudos
Message 5 of 9
(7,417 Views)

@ Lynn. How to create a functional global as you mentioned above? I am also trying to stop 3 parallel loops and want the fastest and most efficient option. Also, When creating an exe, (application) will using functional global work well?

I may not be perfect, but I'm all I got!
0 Kudos
Message 6 of 9
(7,123 Views)

VeeJay,

 

From the LV help page titled "Suggestions for Using Execution Systems and Prioritites":

 

Functional Global Variables

Another way to avoid race conditions associated with global variables is to use functional global variables. Functional global variables are VIs that use loops with uninitialized shift registers to hold global data. A functional global variable usually has an action input parameter that specifies which task the VI performs. The VI uses an uninitialized shift register in a While Loop to hold the result of the operation. The following illustration shows a functional global variable that implements a simple count global variable. The actions in this example are initializereadincrement, and decrement.

Every time you call the VI, the block diagram in the loop runs exactly once. Depending on the action parameter, the case inside the loop initializes, does not change, incrementally increases, or incrementally decreases the value of the shift register.

Although you can use functional global variables to implement simple global variables, as shown in the previous example, they are especially useful when implementing more complex data structures, such as a stack or a queue buffer. You also can use functional global variables to protect access to global resources, such as files, instruments, and data acquisition devices, that you cannot represent with a global variable, since calls to the functional global variable execute sequentially unless you mark the VI as reentrant.

You can solve most synchronization problems with functional global variables, because the functional global VI ensures that only one caller at a time changes the data it contains. One disadvantage of functional global variables is that when you want to change the way you modify the resource they hold, you must change the functional global VI block diagram and add a new action. In some applications, where the use of global resources changes frequently, these changes might be inconvenient. In such cases, design the application to use a semaphore to protect access to the global resource.

 

 

Also, look at Ben's Nugget on Action Engines.  An Action Engine is a super functional globaland is more than you need for stopping your loops.

 

Lynn

0 Kudos
Message 7 of 9
(7,119 Views)

THanks Lynn! THat was helpful. I am currently using Notifiers to stop loops. On highlight execution, I find that all loops have stopped, but the "run" button is still ON, i.e. program is still running. This is so weird, because I am not able to trace which loop is still active because all loops have ended. Stumped!! 😞

I may not be perfect, but I'm all I got!
0 Kudos
Message 8 of 9
(7,114 Views)

Sometimes highlight execution can be deceptive.  Depending on your version of LV and when you turned on highlight execution, the loop which was running at that instant may not show the green arrow but still is running.

 

Do you have an event structure? Might it be waiting for an event before the loop containing it completes?

 

If those clues do not help, then we will need to see your code.

 

Notifiers are a good way to stop loops.

 

Lynn

0 Kudos
Message 9 of 9
(7,110 Views)