mike5 Posted May 20, 2010 Report Share Posted May 20, 2010 Is there a way to get the real numeric type from the Variant, so that it can correctly be cast to either Int or Double? Variant To Data silently converts for you, and I don't want that... Br, Mike Quote Link to comment
Ton Plomp Posted May 20, 2010 Report Share Posted May 20, 2010 The OpenG variant tools supply that info. Ton Quote Link to comment
hooovahh Posted May 20, 2010 Report Share Posted May 20, 2010 Never knew that OpenG had that function. I did find what appears to be the same functionality in the vi.lib. <LabVIEW DIR>\vi.lib\Utility\GetType.llb\Get Type of Variant.vi Found that when digging around the TDMS viewer. Using some more code from the viewer you can convert many data types to string. Quote Link to comment
mike5 Posted May 27, 2010 Author Report Share Posted May 27, 2010 Thanks! I'll be putting it to some good use Quote Link to comment
mje Posted May 27, 2010 Report Share Posted May 27, 2010 Also check out vi.lib\Utility\VariantDataType\*. There's a lot of useful VIs in there. Specifically for your case, GetTypeInfo.vi. Quote Link to comment
eberaud Posted December 30, 2014 Report Share Posted December 30, 2014 Reviving this topic instead of creating one... vi.lib\Utility\VariantDataType\VariantType.lvlib seems to be similar to vi.lib\Utility\GetType.llb Is there a reason for both to exist? Is there an old implementation (the llb) and a new implementation (the lvlib)? This whole concept seems very important to understand, I would like to get to the bottom of this. Thanks Quote Link to comment
mje Posted December 30, 2014 Report Share Posted December 30, 2014 The llb is older. I can't remember when the lvlib came around, but it's been around for several versions now. I can't say I'm familiar with the old implementation, but I've used the newer one extensively. Works great. Quote Link to comment
Darren Posted December 30, 2014 Report Share Posted December 30, 2014 The GetType.llb VIs were added in LabVIEW 7.0, and they were used to parse the legacy I16 Array type descriptors. The VariantDataType VIs were added in LabVIEW 8.0, when we switched to using Variants to define data types instead of I16 Arrays. At this time, the internals of the old GetType.llb VIs were updated to use Variants as well. So there's no need to use the VIs in GetType.llb. They are deprecated. And it's a little late in the game, but we are planning on marking them as deprecated in a future LabVIEW version. Quote Link to comment
eberaud Posted December 30, 2014 Report Share Posted December 30, 2014 Great, so I can focus on the lvlib only. Thanks for the info Quote Link to comment
hooovahh Posted January 5, 2015 Report Share Posted January 5, 2015 Yes OpenG also has their versions of getting data type of a variant. It bugged because in version 2011 the OpenG version was about 10 times faster than the NI version from the lvlib, but in 2012 and newer the NI version was about 10 times faster than the OpenG. At one point I had some goofy code that would know the version and pick the right one, but I convinced myself it wasn't worth it and to just go with the native (NI) solution whenever possible. Quote Link to comment
eberaud Posted January 5, 2015 Report Share Posted January 5, 2015 The OpenG does have feature that the NI lvlib doesn't though, like getting the values of the elements of an array. The lvlib GetArrayInfo.vi only gives the element type of the array. So my code uses OpenG when necessary, and VariantType.lvlib when possible, in order to use as much native NI code as possible. Quote Link to comment
drjdpowell Posted January 5, 2015 Report Share Posted January 5, 2015 The OpenG does have feature that the NI lvlib doesn't though, like getting the values of the elements of an array. The lvlib GetArrayInfo.vi only gives the element type of the array. So my code uses OpenG when necessary, and VariantType.lvlib when possible, in order to use as much native NI code as possible. Yes, it’s important to note that NI provides a VariantType library, rather than a full Data library like OpenG does. I wish NI would add the necessary VIs to make its library a complete VariantData solution. I’ve been toying with the idea of doing it myself. Quote Link to comment
hooovahh Posted January 5, 2015 Report Share Posted January 5, 2015 The OpenG does have feature that the NI lvlib doesn't though, like getting the values of the elements of an array. Are you referring to the Index Array under the VArray palette? I'd recommend using a Variant to Data converting the variant, into an array of variants, then you can use the native array functions to index the values out of the array. Quote Link to comment
drjdpowell Posted January 5, 2015 Report Share Posted January 5, 2015 Are you referring to the Index Array under the VArray palette? I'd recommend using a Variant to Data converting the variant, into an array of variants, then you can use the native array functions to index the values out of the array. Variant to Data will also convert a cluster to an array of Variants; something I did not know for a long time. — James PS> A related idea. Quote Link to comment
hooovahh Posted January 6, 2015 Report Share Posted January 6, 2015 That was a fun little XNode and didn't take much time at all. More people should know about the neat features of Variant to Data when it comes to arrays and clusters. Quote Link to comment
eberaud Posted January 6, 2015 Report Share Posted January 6, 2015 This is really cool. This quick test returned TRUE and TRUE! I guess the Variant to Data didn't exist at the time the OpenG library was made... Quote Link to comment
hooovahh Posted January 6, 2015 Report Share Posted January 6, 2015 I know these existed in 7.x, not sure about 6.x or 5.x which is when most of the OpenG stuff was made. Still it is possible it existed, but because it was a relatively new function, maybe the OpenG community didn't know of its full potential. Quote Link to comment
eberaud Posted January 8, 2015 Report Share Posted January 8, 2015 I see. One thing that still requires OpenG though is the reshape array functions (MultiD --> 1D and 1D --> MultiD). Are you aware of any native LV code to replace those? Quote Link to comment
hooovahh Posted January 8, 2015 Report Share Posted January 8, 2015 The Reshape Array can do that, but you'll likely need some extra math to determine the size of each dimension. But what is wrong with the OpenG solution? Quote Link to comment
eberaud Posted January 8, 2015 Report Share Posted January 8, 2015 I mean the Reshape array that takes a variant as an input and generates another variant as the output, the data manipulation happening on the type descriptor side. The OpenG lib seems to be a bit old, plus you said that it sometimes perform 10 times slower than the LV lib. So I try to avoid it when I can... Quote Link to comment
hooovahh Posted January 9, 2015 Report Share Posted January 9, 2015 I wasn't trying to say all OpenG functions are slow. You should perform your own testing to determine if they work fast enough for you. In any case I started making two XNodes to go from 1D to MultiD array and back but I realized it was much easier to just make a VI that works well enough. Attached is a VI that goes from MultiD to 1D and back in a way that I think is pretty efficient. The only thing I'd try to improve is a better way of knowing an array size of the array. Also this method only supports up to a 5 dimension array. Feel free to add more, but a better solution would be to do it programatically with an XNode. Array Dimension Converter.vi Quote Link to comment
Rolf Kalbermatter Posted January 10, 2015 Report Share Posted January 10, 2015 This is really cool. This quick test returned TRUE and TRUE! I guess the Variant to Data didn't exist at the time the OpenG library was made... It existed at least in 6.1 but you have to consider that while the node maintained appearance and principle operation, its implementation was many times improved to handle various more complex data transformations. Initially it didn't do much more than transforming a variant that was a pretty exact representation of the target data. Quote Link to comment
hooovahh Posted January 12, 2015 Report Share Posted January 12, 2015 consider that while the node maintained appearance and principle operation, its implementation was many times improved to handle various more complex data transformations. That's a very good point. Variants are the first real example of a loosely coupled data type, in LabVIEW, a strictly typed language. I mean sure you can express any data type as an array of bytes, and therefor a string. But still Variants are an interesting thing that I'm guessing had some internal debate at NI on if and how they should be implemented. Quote Link to comment
eberaud Posted January 13, 2015 Report Share Posted January 13, 2015 Initially it didn't do much more than transforming a variant that was a pretty exact representation of the target data. Yes this is what I thought the whole functionality was. Thanks. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.