LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is this style of coding appropriate?

Solved!
Go to solution

Hello all, I have a question about the "style" of programming I am using in LabVIEW. Often I want to pass data and trigger event structures in sub-VIs and then pass data around from sub-Vi to sub-VI via the top level VI. The only way I have been able to achieve this so far is via reference controls and server references. Reading on the forums however, I often read that using controls as a data passing medium is a big no-no. However I have used this style in much larger applications to great effect. I essentially want to know what are the shortcomings of using this style, and is there a better way to achieve the same thing. Please see the attached VIs

0 Kudos
Message 1 of 9
(3,053 Views)

What you are doing here isn't inherently wrong, but that wouldn't be my first choice.  (Although sometimes it is unavoidable.)  Once you decide to update an indicator in this fashion, you must never update it conventionally or risk race conditions.  But in general, it's okay to set properties of a control in a subVI.

 

In fact, a common method of distributing main VI references to subVIs is to make right-click on each reference, create a constant, and put it in a (typedef'd) single cluster.  Bundle the refs to the cluster and you have a cluster of main VI references to pass around!  If it's typedef'd, you can add new references as you need them and all the other instances get updated accordingly.  The downside to this is that cluster can get monstrous if you have a lot of references to pass around.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 2 of 9
(3,044 Views)

I would recommend that you do it another way. This way although not wrong per say, will be incredibly slow as you will have a bunch of UI thread switches with all of the references.

  1. Pass values In and Out of the SubVI.
  2. Use a queue/notifier/channel wire to update values from in the subVI to the Main loop.

The examples folder is your best friend here.

 

mcduff

0 Kudos
Message 3 of 9
(2,995 Views)

As a rough ballpark figure, any Property-Node call is about a hundred times slower than writing to terminal/local variables, or using other communication techniques like User Events or Queues.  This is not a problem if you don’t make calls too often, but is a bottleneck if you are passing data very quickly.  

 

Another thing you might want to look into is subpanels.  Subpanels can be used to “assemble” complex User Interfaces without needing to pass references around.  

0 Kudos
Message 4 of 9
(2,992 Views)

@drjdpowell wrote:

As a rough ballpark figure, any Property-Node call is about a hundred times slower than writing to terminal/local variables,


It is actually in the order of 2000 - 3000 times slower based on my last benchmarks.

 

Personally, if coming from just a subVI (not a parallel loop), then I just pass the value out of the subVI and write to the indicator's terminal.  If it is a parallel loop, I am a huge fan of User Events to send values to the GUI (which should be using an Event Structure already).


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
Message 5 of 9
(2,928 Views)

+1 for user events

0 Kudos
Message 6 of 9
(2,925 Views)

Hi All,

 

Thanks for all of your input and feedback. Some pretty useful information. I'm quite interested in this concpe tof User events to operate event structures in subvis. Can some one provide a toy model example or direct me to some good examples?

 

Thanks!

0 Kudos
Message 7 of 9
(2,874 Views)
Solution
Accepted by topic author QuantumPenguin

QuantumPenguin wrote:  I'm quite interested in this concpe tof User events to operate event structures in subvis. Can some one provide a toy model example or direct me to some good examples?

In LabVIEW: Help->Find Examples.  There should be one in there called User Event Generation.vi.  It is doing everything in a single loop, but you can get the concepts of how User Events work.  You just need to generate an event in your subVI.


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
Message 8 of 9
(2,868 Views)

@QuantumPenguin wrote:

Hi All,

 

Thanks for all of your input and feedback. Some pretty useful information. I'm quite interested in this concpe tof User events to operate event structures in subvis. Can some one provide a toy model example or direct me to some good examples?

 

Thanks!


I was going to change your vis to employ that but, you have some learning to do first. Period.  Lets Start HERE

If you are not familiar with LabVIEW Projects see LabVIEW Core I and the getting started guides

If you are not familiar with Project Templates Start HERE


"Should be" isn't "Is" -Jay
0 Kudos
Message 9 of 9
(2,867 Views)