NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Array Constants in TestStand

Someone on my team would like to set the initial value of a multi-dimensional Array of Numbers.

 

What is the syntax for accomplishing this in TestStand?

0 Kudos
Message 1 of 8
(10,230 Views)

In an expression use SetArrayBounds:

 

SetArrayBounds(Array array, String lowerBounds, String upperBounds)
This function changes the bounds of an array. You specify the array bounds as strings with the syntax "[x][y][z]", where x, y, and z are integer constants.
Parameter 1: The array to redimension.
Parameter 2: A string specifying the new lower bound.
Parameter 3: A string specifying the new upper bound
Returns:     This function always returns 0.

 

Hope this helps.

 

-Jack

0 Kudos
Message 2 of 8
(10,214 Views)

I've got a fairly related question so I think a bump should be ok here.

 

Using the TestStand Sequence Editor I create an array of numbers, call it Locals.Test.  Using the IDE I change the lower bound of this array to be 1.  We'll say the upper bound is 4 for the sake of the example.

 

If I call a Statement step type like

 

Locals.Test = {10,10,10,10}

 

the array bounds will now be 0 and 3.  I just figured out I can change them back to 1 and 4 using the above mentioned SetArrayBounds....but this seems rather clunky.  Any logic or reasoning with this or is this just a 'feature'? 

Message 3 of 8
(10,131 Views)

The notation {10, 10, 10, 10} means to create a 1 dimensional, zero based array with those elements. You are then assigning that array to Locals.Test. Thus it is completely replacing the array in Locals.Test. It's simlar to having a Locals.foo that is zero based and assigning that to Locals.Test. Even if locals.Test was multi-dimensional or empty, the end result of that expression would be the same. Perhaps there should be a syntax for setting existing elements in an array, but that is not currently what that syntax does.

 

Hope this helps explain things,

-Doug

Message 4 of 8
(10,117 Views)

Thanks for your explanation, Could I trouble you for more details?

 

What are other pitfalls when using arrays with non standard bounds (indexed from 1 instead of 0)?  I am currently trying to pass an array of booleans as a parameter to a sequence, and in the sequence editor I see the indices of [1], [2] and [3] for my one-dimensional, three element array.  At runtime, I see the indices are switched back to 0,1,and 2 and I get index errors trying to acces the array with indices of 1,2,3.

 

it doesn't matter if I pass the array by reference or by value.

 

My other complaint is the documentation in the help file for the array functions, it doesn't specify types for the parameters.  After adding the setarraybounds() with the properly formatted string arguments, the sequence works. 

 

I feel like I shouldn't have to reset the bounds in an expression, having defined the array in the sequence editor already.

0 Kudos
Message 5 of 8
(9,874 Views)

I'm not able to reproduce the problem you are describing. Which array did you set to start at 1? The parameter or the one you are passing when calling the sequence? The parameter is just a place holder and does not affect anything, the argument you are actually passing for the parameter is the array that matters. If that argument starts at index 1 that is what you will get when you call the sequence.

 

If you think there is still a problem and not a misunderstanding of how things work, please let us know what version of TestStand you are using.

 

-Doug

0 Kudos
Message 6 of 8
(9,856 Views)

I see, the parameter is a place holder as viewed from the Variables window when editing, and I was changing its index bounds there.  While the array I actually passed through was defined by this string "{true, false, false}" in the step settings window of the sequence call step.  This definition defaults to 0-indexed, and only at runtime did I see that by using the Variables window.  This was my trip-up.

 

I guess parameter type checking verified that the array was the right size and type, but indexing is not checked.

 

This should help remind me to avoid using the parameter's default values, too. 

 

Thanks for your help.

0 Kudos
Message 7 of 8
(9,844 Views)

Yep. The dimensions for the parameter place holder can be completely different than what is passed in. The only thing checked is that the type is the same (i.e. that it's an array of the same type).

 

-Doug

0 Kudos
Message 8 of 8
(9,839 Views)