Example Code

Manipulating Multi-Dimensional Arrays in TestStand Expressions

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • Teststand

Code and Documents

Attachment

 

Overview

You can perform basic manipulation of multi-dimensional arrays using the TestStand expression language, but more complex tasks are better suited for a code module.  This example shows how you can perform basic manipulation on a multi-dimensional array.

 

Note: For manipulation of single dimensional arrays, refer to Example: Manipulating Arrays in TestStand Expressions

 

Description

You can perform the following operations on multi-dimensional arrays within the expression language:

  1. Initializing an array
  2. Obtaining an array subset
  3. Setting an Array Element
  4. Clearing All Elements

The following more advanced changes should be performed in a code module with more robust array manipulation capabilities, such as a LabVIEW VI or .NET assembly:

  1. Inserting columns or rows
  2. Deleting Columns or Rows
  3. Replacing a subset of the array

These tasks are not included in this example.

 

Initializing an Array

Initializing a multi-dimensional array using an array literal is not possible directly since the array literal format only supports single dimensional arrays.  However, TestStand does provide a way to reshape a single dimensional array into a multi-dimensional array, which you can use to initialize a 2D array:

 

Locals.Array2D = {1,2,10,20,100,200},
Locals.Array2D.Type.ArrayDimensions.SetBounds({0,0},{1,2})

You can use a similar technique to initialize a large array to a single value, using the single dimensional array functions to generate the elements, then reshaping it into a multi-dimensional array:
Locals.Array2D={},
SetNumElements(Locals.Array2D, 100),
SetElements(Locals.Array2D, 24),
Locals.Array2D.Type.ArrayDimensions.SetBounds({0,0},{10,10})

 

Obtaining an array subset

You can access a single row or column of an array using the ".." notation, as shown:

 

Locals.SingleColumn = Locals.Array2D[0..][1],
Locals.SingleRow = Locals.Array2D[0][0..]

 Using "[0..]" will obtain the entire row.  Alternatively, you can specify a range of elements, such as "[2..3]" to obtain a subset of a row or column

 

Setting an Array Element

You can set individual elements using the following syntax, similar to single dimensional arrays:

Locals.Array2D[1][2] = 222

Clearing All Elements

Similar to a single dimensional array, you can clear a multi-dimensional array using an empty array literal.  

Locals.Array2D = {}

 

Hardware and Software Requirements

TestStand 2014 or Compatible

 

 

Steps to Implement or Execute Code

  1. Open the attached example to see the methods demonstrated in this document.
  2. Run the sequence using Execute » Run Mainsequence
  3. To view the 2D array result, you can place breakpoints after each step the sequence before executing. Once the breakpoint is hit, view the value of Locals.Array2D

 

Kurt P
Automated Test Software R&D

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
testdesign
Member
Member
on

Thanks Kurt for posting.  Could you please resave the seq file at 2013 test stand version?  I have 2013 and can't open the 2014 file.