LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reflection-like operations for VIs?

Solved!
Go to solution

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.

 

 

 

 

0 Kudos
Message 1 of 13
(4,883 Views)

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...


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
Message 2 of 13
(4,862 Views)

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.

 


Message Edited by Jarrod S. on 12-18-2008 10:40 PM
Jarrod S.
National Instruments
Message 3 of 13
(4,850 Views)

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.

0 Kudos
Message 4 of 13
(4,820 Views)

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 Smiley Mad 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.

 

 

 

0 Kudos
Message 5 of 13
(4,796 Views)

This isn't a complete answer, but here is how to get some of that info

 

 

Putnam
Certified LabVIEW Developer

Senior Test Engineer North Shore Technology, Inc.
Currently using LV 2012-LabVIEW 2018, RT8.5


LabVIEW Champion



Download All
Message 6 of 13
(4,787 Views)

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.

 

Message Edited by SPM on 12-20-2008 08:18 AM
0 Kudos
Message 7 of 13
(4,769 Views)

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...


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
Message 8 of 13
(4,728 Views)
Solution
Accepted by topic author SPM

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.

 

Message 9 of 13
(4,709 Views)

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.

 

 

Message Edited by Jarrod S. on 12-22-2008 09:28 AM
Jarrod S.
National Instruments
Message 10 of 13
(4,674 Views)