LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Type issues in LV

I have two related questions about the way LabView handles data type.

I would like the user to be able to connect to a terminal of a VI data of "anything" type (same type as the input of "To variant" node). How can I do that?

What can I use as a container to store a meaningful descriptor of any(undefined at the design time) data type? Meaningful is such that is usable at converting either variant or flattened string data type into the LV data during the runtime.

I couldn't find answer to those questions myself, and they look to me as a main desqualifier of a LabView from being a general purpose programming language.

I would greatly appreciate your help.

Michael
0 Kudos
Message 1 of 11
(3,751 Views)
For your first issue, you need to create a polymorphic VI.

Quote from the online help: "Polymorphic VIs accept different data types for a single input or output terminal. A polymorphic VI is a collection of subVIs with the same connector pane patterns. Each subVI is an instance of the polymorphic VI."

Basically, you must create seperate VIs for each possible input, then combine them into a polymorphic VI.

Could you give a bit more details about your second question? It is not clear to me what you want to do.

About your comment about "LabVIEW as General purpose language", please have a look at this article
0 Kudos
Message 2 of 11
(3,751 Views)
I cannot use polymorphic VIs as I do not know at the design time all possible data types during run time. Besides, use of polymorphic VIs is cumbersome. However, I know answer for the first question already.

The second question deals with inability of LabView (to my knowledge)to provide a way to explicitly access the data type of data in variant during runtime. I did not find a simple way to compare two varians (for example, I would like two variants of same data types but having different data values give TRUE, i.e. equal, on comparison).

Hope it clarified the original question a bit.

Thank you for the help,
Michael
0 Kudos
Message 3 of 11
(3,751 Views)
There are two ways that you can create a VI with a terminal that mimics the behaviour of the "anything" type. The first is to create a Polymorphic VI. This allows you to know exactly what kind of data was wired into the VI. Of course, the drawback is that you must create a new version of your VI for each data type that you wish to support. This is difficult to do if you want to allow for complex types. If you want to allow for complex types, or you don't know yet what types can be wired in, this will prove impossible.

The other way is to create a VI with a variant control that will be your polymorphic terminal. On the block diagram of your VI, you will want to drop the "Variant To Flattened String" primitive (Functions->Advanced->Data Manipulation->Vari
ant). This primitive will provide you with both a flattened string of data (the "data string" terminal) and a type descriptor (the "type string" terminal). Use the type descriptor to determine what kind of data you have. If you follow the help links on the primitive (click on "Click here for more help" in the context help window and then on "LabVIEW Data Storage"), you'll get to an App Note that explains how LabVIEW stores its data. The first part (pages 1-8) explains the data format and the second part (pages 9-14) explains the format of the type descriptors.

You'll have to parse the type descriptor yourself, but there is an LLB buried inside vi.lib (vi.lib\Utility\GetType.llb) that you may find moderately helpful. There is a VI there named "Get Type Of Variant.vi" that returns a type descriptor for the real data inside the variant (if you use this, you may not need the primitive I mentioned earlier). If your data uses containers, like the array or cluster, you'll need to wri
te some parsing code yourself to get to the nested types. Once you figure out your data type, you can then inflate the data.

Hope this helps.

Stephen
0 Kudos
Message 4 of 11
(3,751 Views)
To some extent, you can compare two variants using Equal? comparison nodes. There are some issues as 0.0(DBL) will be different from 0(U32) and NaN(DBL) will be equal to NaN(DBL) (IEEE spec requires that (NaN == NaN) should return False).

Take a look at LabVIEW Data Tools in the OpenG Toolkit at http://openg.org . There are tons of VIs to manipulate variant data.


LabVIEW, C'est LabVIEW

0 Kudos
Message 5 of 11
(3,751 Views)
Thank you for the assistance.

Unfortunately, Equal? does not do what I need: if values of two variants are different, but types are the same, Equal? gives FALSE, even though I need TRUE.
0 Kudos
Message 6 of 11
(3,751 Views)
>The other way is to create a VI with a variant control
>that will be your polymorphic terminal. On the block
>diagram of your VI, you will want to drop the "Variant
>To Flattened String" primitive
>(Functions->Advanced->Data Manipulation->Variant).
>This primitive will provide you with both a flattened
>string of data (the "data string" terminal) and a type
>descriptor (the "type string" terminal). Use the type
>descriptor to determine what kind of data you have.
>If you follow the help links on the primitive (click
>on "Click here for more help" in the context help
>window and then on "LabVIEW Data Storage"), you'll get
>to an App Note that explains how LabVIEW stores its
>data. The first part (pages 1-8) explains the data
>for
mat and the second part (pages 9-14) explains the
>format of the type descriptors.

This is essentially what I would do as well. There is already a toolkit available to manipulate variant data on the OpenG website (www.openg.org). It is part of the OpenG toolkit and is named lvdata. It has VIs for operating on arrays, clusters and more.

Hope it helped

PJM


  


vipm.io | jki.net

0 Kudos
Message 7 of 11
(3,751 Views)
Thanks a lot, it helps.

How come NI did not address this issue yet?! They got to have a universal "GetTypeofVariant" thing somehwere there, I am pretty sure.

Regards,

Michael
0 Kudos
Message 8 of 11
(3,751 Views)
What's wrong with Equal? returning FALSE when values are different???
You want to compare values or types?
To compare if two variants are of the same (sub)type, you have to compare type descriptors of the data. You can't compare type descriptors directly (array of I16) because it also contains information on data name (from control label) that is not relevant for type comparison.

Using LabVIEW Data Tools Get Default Data from TD you could set both variant to compare to their default values and then compare them: if they are not equal, the type is different. You could also use Get TDEnum from Data (that returns the data type as an enum) to compare datatypes and recurse into elements for arrays and c
lusters. A compare type VI would be a nice addition to LabVIEW Data Tools.


LabVIEW, C'est LabVIEW

0 Kudos
Message 9 of 11
(3,751 Views)
MichaelS wrote:
> Thanks a lot, it helps.
>
> How come NI did not address this issue yet?! They got to have a
> universal "GetTypeofVariant" thing somehwere there, I am pretty sure.
>
> Regards,
>
> Michael

Can't you do all this with references? After all, the terminal could be
a reference to a generic control. But LabVIEW is a strongly typed
language, so what you want to do is not an issue, that is why it is not
addressed. The 'universal' solution is to create your own language that
solves your problem and then implement an interpreter or compiler in
LabVIEW, as Turing did in on his infinite tape.
0 Kudos
Message 10 of 11
(3,751 Views)