12-18-2019 02:05 AM - edited 12-18-2019 02:18 AM
Hello the forum,
how can I convert a variant data to specific data type using typedef control reference?
See example VI and CTL inside the the archive.
Thanks!
12-18-2019 02:18 AM
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).
12-18-2019 02:22 AM
@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
12-18-2019 02:32 AM
I'm not sure if you mean like this:
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?
12-18-2019 02:44 AM - edited 12-18-2019 02:49 AM
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
12-18-2019 02:57 AM
12-18-2019 03:54 AM
@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?
12-18-2019 06:58 AM - edited 12-18-2019 07:01 AM
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..
12-18-2019 07:35 AM
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.
12-18-2019 07:38 AM
" 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