Example Code

Stop of multiple while loops - simple functional global

Code and Documents

Attachment

Download All

All LabVIEW programmers have run across this problem: Need to stop multiple while loops, as illustrated below

Intro problem.png

Local variable and property node value require that you remove the latched function on the Stop button with the consequence that you need to manage the on-off state either manually or programmatically – generally a nuisance. You can use a global variable, but again you need to initialize it properly when you start the vi's. There are more advanced methods using queue, notifier, occourrence https://decibel.ni.com/content/docs/DOC-5211 and functional global https://decibel.ni.com/content/docs/DOC-18262

Below is a method also based on a functional global or action engine which is very simple.Here are a few use cases,

Simple use cases.png

The Stop vi is placed at the while loops stop node and at the master loop the action value is set to “Stop”. All other instances use the default function"Query". The simplest use case for a slave loop is shown at the bottom left. Bottom mid shows that the local loop can be set to stop on an error, and bottom right shows that a local stop condition can also be applied.

And this is the "Stop while loops.vi":

Stop multiple while loops (Stop).pngStop multiple while loops (Query).png

The Vi is extremely simple, easy to adapt or make even simpler. Note that it may be used to stop all vi’s loaded into memory. I.e. not only while loops in the same Vi can be stopped.

Be aware that the while loops have to be "well behaving" as the loop is only stopped if it actually executes the

"Stop while loops.vi". Just as with a normal stop button connected to the stop node.

As opposed to using a global variable - the "Stop While Loops.vi" does not need explicit initialization and can be called in any order: Master first or slave first - it does not matter.

The attached demo project illustrates some of these use cases. The "Stop While Loops.vi" alone can be downloaded separately.

I tried to find if someone has published a similar method, but did not succeed. But surely it’s out there, so now there is yet another example.

Hope its useful.

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
crossrulz
Knight of NI Knight of NI
Knight of NI
on

I submitted something very similar to OpenG.  You can have a look at it over on LAVA: http://lavag.org/topic/16171-new-messaging-vis/



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Contributors