LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Variant To Data Cannot Downcast VI Server Refnum

I noticed the "Variant to Data" function does not work as one could expect when casting VI server refnums.

Indeed, if I have a refnum of a specific class (e.g. Numeric) that I upcast to a generic class (e.g. GObject), then feed it to the function to cast it back to a lower class (e.g. Control), it simply throws an error...

 

Variant To Data Cannot Downcast VI Server Refnum.PNG

 

Is it an expected behaviour ? I always thought "Variant to Data" just used the same behaviour as "To More Specific Class" / "To More Generic Class" when dealing with VI server refnums.

The upcasting however works fine...

 

The reason I am not using these 2 last VIs is because the input data I want to cast can be of any complexity (e.g. clusters that contain refnums AND non-refnum data), and the refnums may have been previously upcast.

0 Kudos
Message 1 of 8
(3,309 Views)

The error is because a GObject Ref (your input to Variant to Data) is not a Control Ref.

Do it like this:

cc.png

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 2 of 8
(3,285 Views)

Yes but in this case, "Variant to Data" should be able to convert the GObject to a Control since it IS a Control (and more specifically a Numeric).

As it is, it just seems like this part of the conversion has not been implemented...

 

And to repeat what I said, I'm searching for a generic solution that could work for data types of any complexity (like nested clusters, arrays, containing refnum and non-refnum data), so using "To More Specific Class" after Variant To Data is not helpful.

 

Here is a better example to illustrate my needs :

Function1 will always fail as "Variant To Data" cannot downcast the refnums, even if the actual data type of the passed value DOES match.

Version with more complex data and several functions.PNG

 

0 Kudos
Message 3 of 8
(3,278 Views)

Look at the Data Type Parsing Palette for inspiration.

Snap8.png

Here is a simple way to find the kind of reference, it's generic because you made it generic.

 

Snap7.png

You will need to write something to handle all of the possible cases for your cluster.

 

mcduff

0 Kudos
Message 4 of 8
(3,266 Views)

@raphschru wrote:

Yes but in this case, "Variant to Data" should be able to convert the GObject to a Control since it IS a Control (and more specifically a Numeric).

As it is, it just seems like this part of the conversion has not been implemented...

 

And to repeat what I said, I'm searching for a generic solution that could work for data types of any complexity (like nested clusters, arrays, containing refnum and non-refnum data), so using "To More Specific Class" after Variant To Data is not helpful.

 

Here is a better example to illustrate my needs :

Function1 will always fail as "Variant To Data" cannot downcast the refnums, even if the actual data type of the passed value DOES match.

Version with more complex data and several functions.PNG

 


Be careful what you wish for, you just might get it.

 

I wrote this Nugget 12 years ago that takes on that task.

 

I posted code that will write an (semi) arbitrary cluster of any type that includes cluster and arrays (up to 2d) and arrays of clusters of arrays ad nauseum (sp?) to an ini file and restore same.

 

That was written before all of the functions that McDuff shared. Those were introduced to fill the gaps that I had to fill with my example included in that Nugget. So start with what he shared because doing it the way you are attempting will lead you down the road I described in my old Nugget. If nothing else read over that Nugget and follow-up post to see what you are getting yourself into. (Back in LV 8.2 we had to code using stone knives and bear skins)

 

If there is newer better way to do, use it!

 

Ben

 

 

 

 

 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 5 of 8
(3,239 Views)

It seems to me that you should fix the "User Input" part.  Your "Function 1" handler is expecting a cluster containing an array of control references,

but your "User Input" is sending an array of generic references.  If "Function 1" can only handle an array of control references, you should only send it an array of control references.  If you want to send it an array of generic references, you should make the "Function 1" be able to handle generic references.  You're putting a square peg inside a cylinder, trying to pound the cylinder into a square hole, then complaining that it doesn't fit.

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 6 of 8
(3,225 Views)

@paul_cardinale wrote:

...  You're putting a square peg inside a cylinder, trying to pound the cylinder into a square hole, then complaining that it doesn't fit.


Just use a bigger hammer. Smiley Wink

 

Spoiler

 

 

 

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 7 of 8
(3,219 Views)

You should be making a cluster of control references (preferably typedef'd) and not an array.  That way, you can access each control ref directly, instead of going through such convoluted code.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 8 of 8
(3,209 Views)