LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to have undefined type input for a sub-VI ?

Hello,

 

I'm under LabView 8.5.1, and I would like to have the ability to have undefined type input for a subVI, like the some LabView functions. To see what I want, I give you the example of all notifier functions allow undefined data in input, or the functions which allow to write binary files ...

 

I try to find some solutions, and, find one ( but, It is not very good, IMHO): I use variant data in entry, and I use the functions "ToVariant", and "VariantToData".

 

So, there is a better way to do this ? 

 

Thanks a lots,

rob

0 Kudos
Message 1 of 11
(4,201 Views)

Hi Rob,

you can also use a "normal" string input. You can use the "Flatten to String" and "Unflatten from String" funtions to create a string or to get your data out of a string. How do you send the "real" type into you subvi, to decide which data type you need for the transformation? If you use Variant, then you can read it out of the variant data.

Why do you need a undefined type input? Maybe a polymorphic vi will also work for you.

 

Mike

0 Kudos
Message 2 of 11
(4,195 Views)

Do you want the data type to be variable at run-time, or just while editing (like the NI functions you mentioned)? I think the Variant is a good way to do it if you want to use the same VI with different data types (for example, with Action Engines). Alternatively, flattened strings are another method to achieve the same effect. If you know the data will be a fixed type at run-time, but would like to use the same vi with different types while editing, you want a Polymorphic VI. You create this by essentially creating a bunch of VI's to handle all the datatypes you care about, and then bundling them together so that you just drop the polymorphic vi, and it automatically adapts to the type of data that you wire to it.

 

Chris

Message Edited by C. Minnella on 04-23-2009 09:05 AM
0 Kudos
Message 3 of 11
(4,191 Views)

MikeS81 wrote:

Hi Rob,

you can also use a "normal" string input. You can use the "Flatten to String" and "Unflatten from String" funtions to create a string or to get your data out of a string. How do you send the "real" type into you subvi, to decide which data type you need for the transformation? If you use Variant, then you can read it out of the variant data.

Why do you need a undefined type input? Maybe a polymorphic vi will also work for you.

 

Mike


Those are all of the correct answers for this quesion!....

 

Before LVOOP was introduced. Smiley Wink

 

Using a

 

Controls >>> Variant & Class >>> LabVIEW Object

 

will allow passing any LVOOP data type (even the ones you have not invented yet! Smiley Surprised ).

 

The beauty of using LVOOP is that I don't have to explicitly "decide which data type" because LVOOP does this for you!

 

I'll stop there because I have used up my quota of exclamation points for a single posting.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 4 of 11
(4,185 Views)

Hello MikeS81!

 

Using "Flatten to String" and "Unflatten from String" don't resolve my problem ( eh, I think, if I well understand your answer). I put under a very simple ( and a little bit stupid) example:

 

This example is very basic, but, it shows my problem. It doesn't work, LabVIEW tell me that a wire is broken ( the black one ). However, the function write to binary allow any type of data in its input. One point which is important, I will do nothing on the data itself ( so in this case, I needn't to know the type of data).

 

There is a solution to do what I want to do, without use "flattern to string", or "ToVariant" ?

 

Thanks for your answers!

0 Kudos
Message 5 of 11
(4,173 Views)

I'm sorry. I'm not following what you are trying to illustrate here. What you've done is connect an empty cluster to the binary write function. An empty cluster has no data type (it is not a data type), so that won't work. Maybe it would be easier if you described what you actually want to do? A flattened string is perfectly acceptable way to write arbitrary data types to disk (if that is what you are tryting to do). A flattened string has a data type, so it is set at run-time (even though you can represent other data types this way, the wire actually going into the write binary function is a static type, string). Same with a variant.

 

I still think Polymorphic VIs may be what you are after, but I'll wait to hear more.

 

Chris

Message Edited by C. Minnella on 04-23-2009 09:32 AM
0 Kudos
Message 6 of 11
(4,167 Views)

Yeah, I just ask my collegue ( about the meaning of polymorphic) , what I want is "How to do polymorphic VI ? "

 

EDIT: Okay, now, I have the good question, I can start to search some solutions on the web, with the good keywords.I will repost if I have some difficulties ... Thanks for your answers!

Message Edited by R0b1n on 04-23-2009 08:45 AM
Message 7 of 11
(4,157 Views)

Okay, I'm currently documenting about polymorphic VIs... The main concept is to gather some similary sub-VI into one VI. But, we need one VI for each type of data. So if I want to use my polymorphic VI with a new type, I must add a new sub-VI into my polymorphic VI. ( Am I understable ?).

 

I don't want to make a sub-VI for each type. There is a way?

 

I put under a concrete example of how I do actually to send untyped data into a function (see the case structure, not the while structure):

 

So, I use variant. There is a way to not use variant ? I want to be able to write anytype of data, without have one sub-VI for each type ( in  the case of polymorphic VI)

 

Thanks

0 Kudos
Message 8 of 11
(4,138 Views)

R0b1n wrote:

Okay, I'm currently documenting about polymorphic VIs... The main concept is to gather some similary sub-VI into one VI. But, we need one VI for each type of data. So if I want to use my polymorphic VI with a new type, I must add a new sub-VI into my polymorphic VI. ( Am I understable ?).

 

I don't want to make a sub-VI for each type. There is a way?

 

I put under a concrete example of how I do actually to send untyped data into a function (see the case structure, not the while structure):

 

So, I use variant. There is a way to not use variant ? I want to be able to write anytype of data, without have one sub-VI for each type ( in  the case of polymorphic VI)

 

Thanks


No you will have to write one version for each data type.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 9 of 11
(4,133 Views)

Arf, ok, so it's impossible ...

 

So, thanks all for your answers !!!

 

@+

rob

0 Kudos
Message 10 of 11
(4,127 Views)