10-19-2010 10:42 AM
Hello!
I want to construct a subvi which takes an arbitrary number of parameters of varying data types. My current approach is to let the parameters be bundled into a cluster that is then parsed in a loop:
"Cluster" is a test cluster, "String" and "Digital" are indicators for checking values. The event structure is there for stepping through the loop.
My problem is that I need a way to discern between integers and doubles, but when I extract them from the cluster they're both represented as "digital".
Is there an easier solution that I've missed?
Solved! Go to Solution.
10-19-2010 11:04 AM
LabVIEW is a strictly-typed language so there's no good way to handle generic data.
That said, you can determine the type of data stored in a variant using the tools found in vi.lib\utility\VariantDataType\VariantType.lib (available since LabVIEW 8.2 or so). Instead of using a reference to get at the controls in the cluster, you use GetClusterInfo to get an array of variants, each representing one item in the cluster, then loop through that array and use GetTypeInfo to determine the type of data it contains.
10-19-2010 11:13 AM
Use type descriptors. Look up type descriptors in labview help. Then use properties nodes to get the type descriptors for each control.
10-20-2010 06:58 AM
Thank you for your quick answers. I couldn't get the GetClusterInfo VI to work, but using type descriptors sort of worked. Since there are so many different descriptors, I chose to adapt my current version. It's not perfect but does the job:
This way I don't have to do a bunch of manual, cryptic decoding. If the class is "Digital", I check the type string.
If you have any more comments, they're much appreciated. Otherwise I have a solution now that I'm happy with.
10-20-2010 11:15 AM
I should have checked a bit more carefully - I didn't realize that going through GetClusterInfo you lose the values and only have the data type. However, you might find it easier to use GetTypeInfo on the variant coming out of the property node to determine its type.
Also, check out the Read/Write Anything VIs from Moore Good Ideas, which includes code that converts a cluster into an array of variants with data. A few of the VIs are password protected but appear to duplicate functions found in the VariantDataType library.
10-20-2010 11:32 AM
OK, thank you.