12-18-2008 04:59 PM
Hi, all,
I'm trying to figure out a way to perform a reflection-like operation on a VI: to get its name and the types of its controls and indicators. VI Strings.export gives me almost what I need, but the XML seems to be a bit malformed (Firefox and Internet Explorer won't open it) and it's a tad more information than I need. Is there a more direct way to walk the pinouts and their internal structure?
Thanks,
- Steve.
Solved! Go to Solution.
12-18-2008 08:41 PM
I'm not sure what you mean by a "reflection-like operation", but if all you want is the name of a VI and a list of its front panel controls and indicators, all that information is available through properties. What is it exactly that you need to do?
Mike...
12-18-2008 10:36 PM - edited 12-18-2008 10:40 PM
Like Mike said, you can use a property node of the front panel to get an array of references to its controls. The property is called Controls[ ]. You can use these references to get property names, and whether they're controls or indicators rather easily.
The more tricky part is figuring out their data types. To do this, you'll need to take a few steps. First, read the Value property of the generic control reference. Since this is generic, the data type output of this property node is a Variant data type. But there are reflection functions available in vi.lib for determining the data type of data in a Variant wire.
These functions can be found at <LabVIEW>\vi.lib\Utility\VariantDataType. I haven't used them much personally, but generally you can call a function which will return an enum with the top-level data type of the data. Sometimes this is something directly useful like Boolean, and sometimes it returns something like Array or Cluster, which requires you to call an additional function to peak at the data values in the container.
It takes some leg work, but it's all there and should get you going.
12-19-2008 08:31 AM
To answer Mike's question, I'm trying to generate TestStand scripts. TestStand will be calling LabVIEW VIs that are in an interface library. So I need to get the type signature of all VIs in that library.
I'm not quite sure how to get the controls from VI references, but maybe that'll become apparent if I play with it.
Thanks,
- Steve.
12-19-2008 06:07 PM
Well, I've spent all day trying to get it to run. To traverse clusters, I had to emulate recursion using an array hacked into a stack and I can make that work since it's necessary. But now I think I've hit a brick wall.
Among all the other stuff that needs to be done to make reflection work, I need to get the names and types of the elements of a cluster. GetClusterInfo.vi does not return the names, just the types.
Is there a workaround?
Thanks,
- Steve.
12-19-2008 08:39 PM
This isn't a complete answer, but here is how to get some of that info
12-20-2008 08:08 AM - edited 12-20-2008 08:18 AM
Thanks, LV_pro.
I'm getting the impression that LabVIEW might just be the wrong tool to analyze a VI library. After all, the LabVIEW adapter in TestStand and presumably other tools are doing the same job, because you can import LabVIEW type signatures as typedefs in TestStand. In Java or C#, I could have had a similar job done in a couple of hours.
Would this job be easier to do from, say, C# by using LabVIEW as an ActiveX server? Does anyone here know how to go about this?
Thanks,
- Steve.
12-21-2008 10:52 AM
Once you have a reference to a cluster, look at the controls[] property, it's an array of control references the items in the cluster. Use those references to get information on the items.
Mike...
12-21-2008 06:55 PM
After some more banging on it, I have the core of a solution that works well enough. Most of the complex datatypes other than clusters are either unimplemented or untested, but clusters and the simple datatypes should provide a key to anyone who needs to do similar things.
Key was to find a way to keep everything as references rather than taking values as it was being dissected.
Thanks to all,
- Steve.
12-22-2008 09:28 AM - edited 12-22-2008 09:28 AM
Good work!
One thing that might make your life easier in the future is being able to get an enum's selected string value automatically in LabVIEW, rather than having to type a lot of string constants to put in a case structure. The trick is to use Format to String and wire in the enum value.