LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Convert variant data to specific data type using typedef control reference

Hello the forum,

how can I convert a variant data to specific data type using typedef control reference?

 

aRCo_0-1576656331003.png

 

See example VI and CTL inside the the archive.

Thanks!

 

 

 

0 Kudos
Message 1 of 12
(7,077 Views)

It looks like you've already gotten the bulk of this done.

If you want to get specific data, you need your conversion to include the data (so the cluster you're wiring should have the specific data, and don't use a Variant. Otherwise, use Variant to Data twice (with the current cluster, then on the variant output by that conversion with the "Data" typedef.

 

If you instead mean the "Generic VI Reference", you need to change the reference to have a specific type by right clicking on the reference and choosing "Strictly Typed VI Reference". This may require that you browse for a path (simplest method) or specify the connector pane (I believe this is possible but I've never tried, I always browse. It doesn't have to be the same VI, just the same connector pane).


GCentral
0 Kudos
Message 2 of 12
(7,062 Views)

@cbutcher wrote:

Otherwise, use Variant to Data twice (with the current cluster, then on the variant output by that conversion with the "Data" typedef).


That's what I want! But I miss how to get out of a control reference the data type that I will wire to the Variant to Data VI

0 Kudos
Message 3 of 12
(7,053 Views)

I'm not sure if you mean like this:

Test.png

Here the value I'm putting into the top of the VtD node knows about the data type it contains, so the To Variant node is unnecessary (as shown in 4->3 case, sorry for inverted order of numbering...)

 

If you don't have this information (because you need a variant, it might be a different datatype etc) then you could perhaps give the qualified name of the typedef and use the VI Server to open a reference by name?


GCentral
0 Kudos
Message 4 of 12
(7,039 Views)

None of the methods you proposed could work.

 

In my case, the method to convert the variant to data shall use the reference to the typedef. So, is there a way to get from a typedef control reference the data type (or the value)?

 

In the picture, what I try to realize

aRCo_0-1576658923257.png

0 Kudos
Message 5 of 12
(7,031 Views)

Ah. Yes. Use the Property Node and Value property.

Test_BD.png


GCentral
0 Kudos
Message 6 of 12
(7,015 Views)

@aRCo wrote:

None of the methods you proposed could work.

 

In my case, the method to convert the variant to data shall use the reference to the typedef. So, is there a way to get from a typedef control reference the data type (or the value)?

1) Get the value from the generic control reference. That will be a variant. Use To G Data to convert it to the type def of the control.

 

2) Use "To More Specific" on a class reference created from the type def control. Get the value from it, and it will be the specific value.

 

Perhaps you should explain a bit about why you want this and how you're using it?

0 Kudos
Message 7 of 12
(6,988 Views)

I added Global, and above all I merged the suggestions you gave me and obtained this. The Test VI is not complete, it remains to convert back to the original data type using the cluster reference. Is there a solution?

 

The idea behind is to exchange data between a calling VI and a called VI that is part of compiled library (lvlibp). The called VI only need to interpret the data coming from the calling VI, that's why it needs to know the data type. Is this possible without having common dependencies between calling and called, or without cloning the typedef?

 


wiebe@CARYA wrote:

Use To G Data to convert it to the type def of the control.


Do you mean this? If yes it seems to be available only for NXG..

0 Kudos
Message 8 of 12
(6,944 Views)

What will your PPL VI do with this data?

You cannot in general cast to a specific data type without knowing the data type at edit time... What would the wire look like?

 

You can probably use something like a "Cluster" refnum as you already have, but if all you know is that you have a cluster, all you can do with it is what you can do with a non-specific cluster.

 

The OpenG libraries I believe have some additional tools for parsing Variants, but I'm not familiar with any of them. You could also try using Get Type Information from the Variants palette and then going through other VIs on that palette to rebuild your type, but it's quite a bit of work if you have even a moderate range of options.

 

If you have only a specific collection of options, you can just iterate through them and wait for no error from Variant to Data. Sounds like you want a generic solution though...

 

You might have some better luck considering something like an OOP collection of data classes - one "Data Object.lvclass" and a set of "My typedef1.lvclass", "My typedef2.lvclass" children that inherit from Data Object. Then you could cast to a Data Object object and use dynamic dispatch to do something with the elements.


GCentral
0 Kudos
Message 9 of 12
(6,933 Views)

" Is this possible without having common dependencies between calling and called, or without cloning the typedef?"

 

No.

 

But what is wrong with cloning the type def in your book?

 

I have used the "cloning" approach to allow for backwards compatibility.

 

An example is an application that has  PC side and a cRIO side where I need to be able to deploy updates to either side that changes the messaging between the applications.

 

When messages are received the version number of the sender is checked and used to determine which typ def to use to unpack the message.

 

Each time the message format has to change I "clone off" the ""current type def" and freeze it before making changes for the next version.

 

For what it is worth,

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 10 of 12
(6,931 Views)