From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, 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: 

Polymorphic VI changing if an input is not connected

Hi,

 

I would like to have a polymorphic VI that choose one subVI when an input is connected and other one when this input is not connected. Just like the read from binary file VI works. Example: U32 is connected to the data type and count is not connected --> output is ONE element of type U32. Same as before but the data count terminal is now connected --> output is now an ARRAY of U32.

 

How can I create something similar?

 

Thanks

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

I assume you know the usual drill:

 

File->New then choose Polymorphic VI

Create your two subVIs, with and without the count control

Add the two subVIs to the Polymorphic VI, keep the default settings to allow Adaptation

 

The one "trick" if you will is to put the VI without the count control at the top of the list.  During the Type adaptation, VIs are tested from the top of this list downward, stopping at the first one that works.  Being unwired would be considered working, so if you reverse the two, the version with the count control would always match.

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

Hmm, it doesn't seem to work the way I want it to work. The VI that I referred to earlier changes it's output format depending on if the count is connected or not. The connect terminal is always there. I don't want it to disappear.

0 Kudos
Message 3 of 9
(3,265 Views)

 


@mrsound wrote:

Hmm, it doesn't seem to work the way I want it to work. The VI that I referred to earlier changes it's output format depending on if the count is connected or not.


What exactly is not working.  The polymorphic instance with no count terminal can have whatever output format you wish, same for the instance with the count terminal.


The connect terminal is always there. I don't want it to disappear.

By connect you mean count? When does it disappear?

 

0 Kudos
Message 4 of 9
(3,261 Views)

Yes, I meant count terminal, sorry.

 

Have you tried the "read from binary file" VI (I'm using LabView 2009 Fall version) and wired a number (not a string) to the "data type" input terminal? Then looked at the data output terminal and seen that it changes from a single element to an array, when the count terminal is connected. I want this same behavior for my own polymorphic VI. I'm sorry I don't think I can explain it better than this. Smiley Sad

0 Kudos
Message 5 of 9
(3,246 Views)

You have to explain what is not meeting your expectations.  A polymorphic VI with the two instances I described, without Count terminal and scalar output along with Count control and array output will behave very similarly to the Read Binary File VI you mentioned.  The only difference I could see is that the tip strip or context help may not display the Count label.  The terminal is still there and the output will change depending upon whether or not it is wired.

 

If you want something different then put the count terminal in both instances and choose the instance manually.  If you make the development-time choice to leave it unwired, you can make the development-time choice to select the proper instance.

 

Either way is about as close as you are going to get to the functionality of the built-in functions.

 

 

Message 6 of 9
(3,238 Views)

Thank, you. Interesting I cannot see the terminal but it is there when I try to wire it. Smiley Surprised Can I make it show up in both cases?

0 Kudos
Message 7 of 9
(3,234 Views)

I don't really know a clean way of getting it to show up in all instances.  You could for example, put different data type, like an Enum as the Count control instead of leaving it out.  This almost works, except when you try to Create Control or Create Constant from the terminal, which for me, is almost always, you get the wrong data type.

 

If it were me, I would probably just use separate subVIs since there are only two choices.  Polymorphics tend to be worth the trouble only when there are many different choices, typically when you have the same controls in all instances but need several different types.

 

If I were to use a polymorphic VI here, I would probably go with manual instance selection, all things considered.

Message 8 of 9
(3,230 Views)

Ok, thank you for you help. Much appreciated. 🙂

0 Kudos
Message 9 of 9
(3,228 Views)