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.
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.
05-06-2011 11:52 AM - edited 05-06-2011 11:52 AM
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
05-06-2011 01:31 PM
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.
05-06-2011 02:32 PM
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.
05-06-2011 02:43 PM
@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?
05-06-2011 05:02 PM - edited 05-06-2011 05:10 PM
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.
05-06-2011 05:21 PM
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.
05-06-2011 05:29 PM
Thank, you. Interesting I cannot see the terminal but it is there when I try to wire it. Can I make it show up in both cases?
05-06-2011 05:51 PM
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.
05-06-2011 05:54 PM
Ok, thank you for you help. Much appreciated. 🙂