LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

multiple copies of controls

Hello,
   I have a simple question -- so simple that I apologize in advance if it's clearly answered in the official documentation, elsewhere on these forums, etc.  Is there any way to have multiple "copies" of the same control (that is, the exact same instance, not just the same type of control) on a block diagram?  For example, if I can only have 1 copy and I need to use that control all over the place on my diagram, I'll have ugly wires all over the diagram: chaos.  For a specific example, say I have two parallel loops, and I want a stop control to stop both -- can I have two "copies" of the same stop control (one inside each loop structure), or do I have to have only one "copy" (say, outside both loop structures) and then use wires to connect that copy to the end-condition inside each loop?

Thanks,
Drew
0 Kudos
Message 1 of 4
(3,161 Views)

Hi Drew,

      I think what you're after is a "Local Variable" - right-click on the diagram terminal and choose create\local variable.  Locals can be configured for Reading (a data source)  or Writing (a data-sink.)  Old LVers use "locals" sparingly because wiring directly to the (one) control is more efficient for LabVIEW and the wires you seek to avoid may actually assist in debugging (tracing the source of data-changes.) Smiley Wink 

Cheers!

"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
Message 2 of 4
(3,156 Views)

To answer your question; No, there is no way to have multiple copies of a control/indicator.

Local Variables are the easiest way to pass data between Loops, but as mentioned, they are not very efficient and can make things difficult to troubleshoot. They can also introduce race conditions because they do not follow the data flow paradigm that LabVIEW uses.

You also can't have a control outside a loop/loops and read the value inside the loop. With the control outside the loop, the value of that control will be read once before the loops start iterating, that value will be passed into the loops and that value will essentially become a constant inside the loop. The control would have to be read again to get a new value, but since it's outside the loops, it can't.

The best way to pass data between loops is to use Queues, Notifiers or Functional Globals. There are some good examples that ship with LabVIEW show the use of Queues and Notifiers. (Help>Find Example. Search for Queue and Notifier) And there are several article on ni.com you can search for show the use of Functional Globals.

For single loop architectures, you're better off passing everything with a wire. Using a State Machine architecture can keep your diagram neat by passing most, if not all of your data around using clusters in shift registers. This can make your data available everywhere in your application.



Ed Dickens - Certified LabVIEW Architect - DISTek Integration, Inc. - NI Certified Alliance Partner
Using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences.
0 Kudos
Message 3 of 4
(3,147 Views)

Hey Drew,

      A slight clarification...


@Ed Dickens wrote:

You also can't have a control outside a loop/loops and read the value inside the loop. With the control outside the loop, the value of that control will be read once before the loops start iterating, that value will be passed into the loops and that value will essentially become a constant inside the loop. The control would have to be read again to get a new value, but since it's outside the loops, it can't.


What Ed means is: If a control's value is wired into a loop, then the value inside the loop (coming from the tunnel) will always be the same value - the value the control had before the loop started executing.  If a control's value is read via a local-variable it will be the newest/current value, even if the control is changed/updated outside the loop.  The "stop" usage you described is a great example of a simple use for a "local":  here, a notifier or occurance might be used instead but they're probably overkill. Smiley Wink

Cheers!

"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
0 Kudos
Message 4 of 4
(3,139 Views)