LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Beginner's Nugget : Communicating Between Loops

I have been reading several threads lately about getting data out of one loop and into another, and/or from one VI to another. This is a common issue, especially with programmers who are familiar with local and global variables, but want to eschew those methods for performance reasons.

The attached VI is my attempt to get some of the many methods together in one VI for demonstration and experimentation. Your implementation will vary, and likely be more robust (error checking, etc). I have tried to keep it as simple as possible. On a side note, this VI also shows how to stop two loops with one button with no locals (also a common topic).  

You’ll need the three attached VI's. Run "Communicating Between Loops.vi".

 

Can you describe the advantages and pitfalls of these methods? 

 

Richard






Download All
Message 1 of 6
(3,374 Views)

Here's a screen shot (for those that don't have LV2009).

 

CBL.gif

Richard






Message 2 of 6
(3,372 Views)
I would recommend pointing readers to the standard NI KB article of the producer-consumer architecture, as that is the basis for what you've shown. As for the methods, I don't see the point of using notifiers unless you are explicitly trying to stop the one loop from continuing until the notifier has been set.
Message 3 of 6
(3,363 Views)

smercurio_fc wrote:
I would recommend pointing readers to the standard NI KB article of the producer-consumer architecture, as that is the basis for what you've shown. As for the methods, I don't see the point of using notifiers unless you are explicitly trying to stop the one loop from continuing until the notifier has been set.

 

NI's Producer-Consumer example shows one method. My point was to show many.

Regarding the Notifier, thanks for pointing out the main reason to use it. I use Notifiers (quite often) so that a parallel loop doesn't keep spinning and populating stale data.  I know that there aren't too many fans of Notifiers.

Richard






Message 4 of 6
(3,352 Views)

I agree with you in principle, but it practice, your example may cause more harm than good.  While you show many possible methods, there is no discussion of the pluses and minuses of the different methods. Any method which uses globals, locals, shared variables, or direct access via VI server is an invitation to race conditions and will be difficult to synchronize.  They can be used if you know exactly what you are doing, but they are too often used as a shortcut, and then we get questions in this forum about why it doesn't work.  The data value reference, queues, and action engines/functional globals are recommended.  Notifiers are not normally recommended because they are lossy (you can miss a value if the values change too fast).  Notifiers are typically used for broadcasting status.  This is useful to stop loops when no other status will be coming, but it is usually easier to use a command in the normal data stream or a user event.

 

In short, the National Instruments example gives best practice to keep things simple for a new user.

Message 5 of 6
(3,269 Views)

I certainly didn't mean to Do Harm. The point was to get several methods in one place, to see how easy or cumbersome each method is to set up. And (as it says in the OP) discuss the pitfalls and advantages of each method.

 

So, we've established some pitfalls:

  • Notifiers are lossy (use a queue if you care about that).
  • Globals and Locals may cause race conditions. It is important to note that these are also lossy.

 

...

 

 

 

Richard






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