NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I access the Measurement array of a MultipleNumericLimitTest?

Solved!
Go to solution

Here is a Csharp code snippet that I thought should work, but doesn't:



...
PropertyObject item;
...
if (item.GetValString("TS.StepType", 0) == "NI_MultipleNumericLimitTest")
{
string lowerBound, upperBound;
int numElements;
PropertyValueTypes elementType;
item.GetDimensions("Measurement", 0, out lowerBound, out upperBound, out numElements, out elementType);

for (int k = 0; k < numElements; ++k)
{
// **** This next line throws an exception - "Specified value does not have expected type"
PropertyObject arrayEntry = (PropertyObject)item.GetValVariantByOffset(k, 0);

if (arrayEntry.Exists("Status", 0))
{
this.currentResultData.status = arrayEntry.GetValString("Status", 0);
}
...
}
}

Can someone enlighten me as to what I should be doing to properly access the Measurement Array?
0 Kudos
Message 1 of 3
(3,088 Views)
Solution
Accepted by topic author tlaford

I figured it out...



item.GetDimensions("Measurement", 0, out lowerBound, out upperBound, out numElements, out elementType);
...
PropertyObject arrayEntry = (PropertyObject)item.GetValVariantByOffset(k, 0);

... should be ...



PropertyObject measurementProperty = item.GetPropertyObject("Measurement", 0);
measurementProperty.GetDimensions("", 0, out lowerBound, out upperBound, out numElements, out elementType);
...
PropertyObject arrayEntry = (PropertyObject)measurementProperty.GetValVariantByOffset(k, 0);
0 Kudos
Message 2 of 3
(3,083 Views)

It's probably better to call GetPropertyObjectByOffset instead of GetValVariantByOffset, then you won't need the cast and will give a better error message if it's not an array of objects.

 

-Doug

Message 3 of 3
(3,055 Views)