From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I cleanly pass in a bunch of references to a subVI?

Solved!
Go to solution

In a subVI, I use references to grab current control values and change properties of those controls according to those values. I'm only passing three references in, but even if I array them together to reduce input size, they clutter up my block diagram. They're also preventing me from turning some spaghetti code into a subVI, as they dont remain consistent through the edit->create subvi process. Is there some better way to handle this?

0 Kudos
Message 1 of 14
(3,611 Views)

@ijustlovemath wrote:

In a subVI, I use references to grab current control values and change properties of those controls according to those values. I'm only passing three references in, but even if I array them together to reduce input size, they clutter up my block diagram. They're also preventing me from turning some spaghetti code into a subVI, as they dont remain consistent through the edit->create subvi process. Is there some better way to handle this?


The way you describe is the only way I can think of doing it.  I'm curious as to why you feel it's not working correctly if you use "Create subVI"?  I do that fairly often and it just seemed to work.

 

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 14
(3,606 Views)

Often times it just scoops the reference into the subVI, making a brand new control that I don't really care about. That, or leaves that little "mismatched data type" red triangle. I really just wish I could put references into a subVI in order to clean up the diagram, as they look sort of out of of place.

0 Kudos
Message 3 of 14
(3,591 Views)

You could put them into a cluster and unbundle as needed.

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.
Message 4 of 14
(3,583 Views)

Maybe there's a problem with the way you create the subVIs.  Don't incude the terminals themselves.

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 5 of 14
(3,567 Views)

I go for one of the following options:

- Create a non-strict reference terminal on the front panel of the SubVI - useful when it's only one or two references you need.

- Bundle up the references into a cluster and then convert it into a type definition. I can then unbundle any of the references I need within the SubVI. This is good if you want to perform specific actions on specific references in the SubVI (e.g. update string, set colour of button etc.) and it keeps the correct class type

- Create an array of references. This is useful if you want to perform the same action on multiple items of the same class (e.g. setting visible / enabled state which can be done on any control/indicator). They'll get type-casted to the common parent class which means that some specific methods won't be available unless you cast it back inside the SubVI.

 


LabVIEW Champion, CLA, CLED, CTD
(blog)
0 Kudos
Message 6 of 14
(3,439 Views)

Thanks for the help! I've used all 3 methods, but they are still sort of cluttered, as you still have to cluster/array/singly pass the references into the subVI, so the reference terminals are still on the main block diagram. Is there any cluster that contains all of the reference terminals, that when unclustered will retain the class of the control references? I know that upcasting happens when different control references are array together, but I want something that doesn't upcast, so as to avoid having to do the casting myself in the subVI (if only to avoid those little red triangles!).

0 Kudos
Message 7 of 14
(3,412 Views)
Solution
Accepted by ijustlovemath

I like to logically group the references in a pseudo state machine. In state A I bundle into a cluster the group A references, then go to state B where I bundle group B references and so on. I finally have a Cluster of references that can contain logically grouped clusters of references. I make the final cluster a typedef and I usually create a vi template having this cluster as an input.

 

On my BD the references are stacked in multiple state cases taking less space.

 

Ben64

Message 8 of 14
(3,403 Views)
I'm not sure I see what you're talking about. Mind posting the vi/screenshot/code snippet?
0 Kudos
Message 9 of 14
(3,374 Views)

Here's a quick exemple.

 

Ben64

0 Kudos
Message 10 of 14
(3,357 Views)