LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to stop 2 parallel loops

Solved!
Go to solution

Hi all,

 

I have a vi (see example attached) that may be closed in 2 ways:

1) User pressed an "Exit" button (with a LATCH action) on the GUI.

2) User tries to close the panel by pressing the red "X" in the right top corner.

 

The vi contains 2 parallel loops: One main loop, containing the actual code, and a 2nd loop containing a the events for stopping the vi.

 

The problem is, while the "close panel?" event works just fine and terminates the 2 loops, the "value change" event doesn't.

So, when I press the Exit button the vi does not stop.

 

Any good idea how should I implement this?

 

 

0 Kudos
Message 1 of 10
(3,581 Views)
Solution
Accepted by Mentos

From my experience, a ValueChange event is not fired when you write to a local variable.  I see two quick options:

 

You could write the value using the Value(Signaling) property node (which will fire the ValueChange event). 

 

Or you could simplify things a bit and just use one local variable.  I prefer this option.  See attached.

http://www.medicollector.com
0 Kudos
Message 2 of 10
(3,565 Views)

Hi Mentos,

 

if wanna create an event you have to change the value of a control by an Proberty Node (Val(Sgnl)). ->see file

 

I use plenty of parallel loops (1 loop for DAQ, 1 loop for status information, subpanels...) for me the best way

was to use FunctionalGlobalVariables (FGV).

 

I would suggest if U wanna do stuff like this use also FGV.

 

- FGV_Manage_Loops
    here use an enum with states, for example INIT, RUN, CLOSE

 

 

...just painting code
0 Kudos
Message 3 of 10
(3,564 Views)

Hi

 

i would support a Functional global to local variables or property nodes. that is what i commonly use to stop parallel loops.

If uisng a functional global, just ensure that the global is initialized after all the loops are stopped. Or, you can also initialize it before starting any of the loops.

 

Attached is a crude representation of what can be done.

Regards
Freelance_LV
TestAutomation Consultant
Message 4 of 10
(3,557 Views)

Hello Freelancer,

 

Why you need functional Global variable in a VI to stop 2 Parallel Loop.

Here question is talking about two parallel loop not 2 parrallel VI Loops.

 

I think mentos this is not the best way to stop loop. You can go with the above 2 solutions.

Thanks and Regards
Himanshu Goyal | LabVIEW Engineer- Power System Automation
Values that steer us ahead: Passion | Innovation | Ambition | Diligence | Teamwork
It Only gets BETTER!!!
0 Kudos
Message 5 of 10
(3,547 Views)

If your loops are on the same diagram or are in different VIs, using Functional Globals is a good way of sending messages such as stop. If you communicate to your loops using queues then it is probably better to send the message on the queue.

 

You should put the button for the event inside of the event structure in the case that handles the value change event. Also using switches as indicators is confusing. When I first ran the program I tried to click on them. Another thing to watch for is the greedy loop. You should put a wait of some kind in the bottom loop so you don't peg your CPU doing nothing.

 

 

=====================
LabVIEW 2012


0 Kudos
Message 6 of 10
(3,523 Views)

My preference for communicating back to an even structure is to use user events. Using value signaling on controls often ends up with random controls/indicators on front panels whose sole purpose is to fire an event into an event structure. User events are more generic and don't require the extra controls/indicators. In addition, if you create a nice library for them they are easily used in subVIs to communicate back to upper level user interfaces. My applications often have two or three sets of user events. They can be classified as system events (things like stop, start, exit), application specific events and in some cases process specific events. Using local variables will generally lead to race conditions. Functional globals will help to eliminate the race conditions but your system will effectively be a polling system. My preference is for event driven systems so I tend to use queues or notifiers for message passing.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 7 of 10
(3,507 Views)

Specifically for the case of stopping multiple loops, I have developed a small library that combines the Functional Global Variable with Dynamic Events.  I have the FGV send the dynamic event when the stop command is set to true, so any loop can stop all of the loops.  Sorry, it is not ready for realease to the public.  Maybe later this year I can get it into OpenG.


GCentral
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
0 Kudos
Message 8 of 10
(3,501 Views)

I'd like to thank everyone who responded to this thread.

 

The first answer by Josborne actually does the work and is enough for my application.

Thanks for that!

 

Mark, I'm not so familiar with user events. Can I use this method to fire a "panel close?" event, for example?

Can you add some kind of example?

 

Thanks in advance.

0 Kudos
Message 9 of 10
(3,499 Views)

@Mentos wrote:

Mark, I'm not so familiar with user events. Can I use this method to fire a "panel close?" event, for example?

Can you add some kind of example?

 

Thanks in advance.


Not directly. You would have a separate event case for your user event. When I use this approach to avoid duplication of code I have the panel close and application close events simply fire off my "Exit" user event. That way all of my cleanup code resides in one event case. Otherwise if if you duplicate the code you have to maintain multiple copies which is not a very good coding practice.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 10 of 10
(3,489 Views)