LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

pass cluster to sub vi

Solved!
Go to solution
Solution
Accepted by topic author MaxGreisel

0utlaw already covered much of this but I'd hate to waste the screenshots I was making while he was replying so I'll attempt to elaborate a bit with illustrations. Let's say you start with this very-simple diagram:

Flat.png

Now, you decide that you want to turn the negate operation into a subVI, so you select the Unbundle, Negate, and Bundle, and create a subVI. You also want to do the same for the "Add One" operation. LabVIEW will create exactly the subVI we're describing, with a cluster as an input and the same cluster as an output:

Negate.png

Now the top-level diagram looks like this, with the subVIs:

With SubVIs.png

 

In terms of memory use, this is essentially identical to the original flat diagram. It's simple and maintains the execution order of the original as well. If you tried to do this with references, it would be more complicated and you'd need to add logic, or at least an error wire, to enforce the correct order of execution of the subVIs.

 

If the subVI is saved and its front panel is closed (or has been removed, as happens when compiling an application), LabVIEW doesn't make a copy of the cluster contents since there's no need to display it. Even though it seems like there's duplicate data on the front panel, there is actually NO data on the front panel (because it's closed), and the wire just carries the data through as if there was no subVI. You will often see this while debugging - you run your code, then open a subVI's front panel and it just shows the default values because LabVIEW didn't keep a copy for display (I often forget this, and have to rerun my debugging test with the front panel open in order to see the data that was passed into the subVI).

 

There are tricks that help ensure that LabVIEW reuses inputs as outputs, such as setting the input connectors as "required" and placing controls and indicators that are used as inputs and outputs on the top-level of the subVI's block diagram (outside of any case structures, loops, etc). If you want to get into the details, search this forum for "in place".

Message 11 of 12
(683 Views)

Hi guys,

 

I think I finally got it and I will use nathands approach. Thank you very much for you help. I really appreciate it!

 

Best,

Max

0 Kudos
Message 12 of 12
(653 Views)