07-10-2012 04:08 AM
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?
Solved! Go to Solution.
07-10-2012 06:56 AM - edited 07-10-2012 06:57 AM
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.
07-10-2012 06:56 AM
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
07-10-2012 07:07 AM
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.
07-10-2012 07:37 AM
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.
07-10-2012 09:25 AM - edited 07-10-2012 09:32 AM
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.
07-10-2012 10:02 AM
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.
07-10-2012 10:09 AM
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.
07-10-2012 10:14 AM
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.
07-10-2012 10:45 AM
@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.