Solution
You can use two TestStand API methods defined in the PropertyObject class:
- PropertyObject.GetNumSubProperties: This method returns the number of subproperties belonging to a particular object (e.g. number of local variables, sequence file globals, subproperties of a TestStand container, and so on). You can then have a loop with as many iterations as the number of subproperties to get the name of each variable using the PropertyObject method described next
- PropertyObject.GetNthSubPropertyName: This method returns the name of a subproperty that the index specifies.
How to correctly use these methods and pass them the correct reference depends on how your code module is called:
- If the code module is called from a step in a sequence you need to pass the SequenceContext to your code module and use it as the ActiveX reference for the PropertyObject methods described above. Please refer to the following instructions, based on your development environment:
- In LabVIEW, you must first call the SequenceContext.AsPropertyObject method and use the return value as the ActiveX reference for the PropertyObject methods. Pass one of the following values to the lookupString parameter: Locals, Parameters, FileGlobals or StationGlobals, depending on the scope of the variables you want to obtain. Do not use quotes in LabVIEW.
- In LabWindows/CVI, your code might look like:
// Get the number of Local Variables
tsErrChk (TS_PropertyGetNumSubProperties (testData->seqContextCVI, &errorInfo, "Locals", &NumOfSubproperties));
for (Index = 0; Index < NumOfSubproperties; Index++)
{
// Get the Nth variable name and store it in the variable called "VariableName"
tsErrChk (TS_PropertyGetNthSubPropertyName (testData->seqContextCVI, &errorInfo, "Locals", Index, 0, &VariableName));
}
- In .NET, obtain the Locals object using the Sequence.Locals property and then use the PropertyObject methods described above.
- If your code module is not called from any sequence or you need the reference to variables defined in a sequence file other than the one calling your code module, then you will not have the SequenceContext available. In this case, you can use the following methods and properties to get an object to be used as the reference for the two PropertyObject methods listed above:
- To get the Station Globals object: Use the Engine.Globals property.
- To get the Sequence File Globals object: First, you need to get the sequence file object containing the file globals you want to get. Then, retrieve the FileGlobals object. This can be done using the following methods/properties:
- To get the Locals and Parameters objects: Since the local variables and parameters belong to a sequence, first you need to get the sequence file object where the sequence resides. Then, you can get the sequence object and finally the parameters and/or locals object. Use the following methods/properties to accomplish this:
Once you obtain the Locals, Parameters, FileGlobals, or StationGlobals PropertyObject, use that object as the ActiveX reference when calling GetNumSubProperties() and GetNthSubPropertyName(). When using the object directly, pass an empty string ("") to the lookupString parameter.