LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Pass data from event loop to another loop

Solved!
Go to solution

I'm trying to find a simple way to pass data out of an event loop for use elsewhere.  Could someone explain to me why my example below hangs (code attached)?  I feel like I must be missing something simple.  Also, I'd rather avoid queues, if possible, as they seem unnecessarily complex.  Thanks for your help!

 

test_passing_data_out_of_event_loop.png

0 Kudos
Message 1 of 6
(3,760 Views)
Solution
Accepted by ishmael

The second loop will not execute until the first on is done. Use execution highlighting and you can see this. You can use a local or a vi to save the data into. Here is a quick example using a local.

0 Kudos
Message 2 of 6
(3,754 Views)

The queue is the standard and preferred way to transfer data from one loop to a parallel loop. As ErnieH pointed out LabVIEW's dataflow paradigm makes the method you are using sequential rather than parallel.  Look at the Producer/Consumer Design Pattern which comes with LV.  It shows how to use a queue to pass the data.

 

Also, I notice that both your loops are infinite loops (no way to stop). If you are using the Abort button to stop your VI, STOP. The Abort button is for use during development only in case a program hangs. Someone on the Forums stated that "Using the Abort button to stop a VI is like using a tree to stop a car. It works but may have unintended consequences!"  Add a Stop button to your front panel and add an event case for the Stop: Value Changed event.

 

The lower loop may be a greedy loop as well.  When running loops in parallel each loop should have a short delay [Wait (ms)] or similar.  This allows CPU resource sharing between loops.  The event structure provides the delay in the upper loop.  The queue or a notifier can be used to stop the second loop whe the first one stops.

 

Lynn

0 Kudos
Message 3 of 6
(3,747 Views)

@ErnieH: Thanks for the modified VI.  It's quite helpful.  I notice that you had to create an indicator in order to make a local variable.  Is there any way to create a variable to contain the output from the shift register?  (I have no need for an indicator of milliseconds - I suppose I could hide t, but that seems like a hack).  Also, why did you put the stop button inside a sequence?

 

@Johnsold: Ok, maybe a queue really is the way to go.  Thanks for the tip about the timing of the lower loop.

0 Kudos
Message 4 of 6
(3,741 Views)

The wire is technically the variable. Local variables are really functions that act on controls or indicators and therefore cannot exist without them. Global variables on the other hand can exist without a control or indicator. Well there is a control for it but it is in a special VI and not on your VI. But instead of either of those you probably want to check out action engines which are sometimes called functional global variables. The link describes action engine and functional global very well.

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


Message 5 of 6
(3,737 Views)

The stop button is just to stop both loops and end the program. The stop button needs to be inside the loop to get updates. I usually put controls somewhere in a loop so the mechanical action will work. It will not work if it is outside of the loop since it is not executed after the loops start. To use the local variable, you need a control to attach it to. You could use a global, or a vi (action engine). The outside sequence just enforces dataflow so the control is initialized before the loops start.

0 Kudos
Message 6 of 6
(3,715 Views)