Example Code

Creating Arrays using the TestStand API

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

This example shows three methods of how to programmatically create a TestStand Array using the TestStand API.

 

 

Description

This example uses the following approaches to generate a new array using the TestStand API:

 

Creating a copy of an existing array object only at run-time

  1. Access the Run-time  Locals container using "Locals"
  2. Clone the existing object using the Clone() method
  3. Add the new array to the Locals container using the InsertSubProperty() method

Locals.SetPropertyObject("NewArrayFromClone",  PropOption_InsertIfMissing, Locals.OriginalArray.Clone("",0))

 

Creating a new array object only at run-time

  1. Access the Run-time  Locals container using "Locals"
  2. Create a new array and insert it into the Locals container using the NewSubProperty() method

Locals.NewSubProperty("NewArraySubproperty", PropValType_Number, True, "", 0)

 

Creating a new array object at edit-time

  1. Access the Locals container for the edit copy of the sequence file (not the active sequence execution) using "RunState.SequenceFile.Data.Seq["MainSequence"].Locals"
  2. Create a new array and insert it into the Locals container using the NewSubProperty() method

RunState.SequenceFile.Data.Seq["MainSequence"].Locals.NewSubProperty("NewArraySubpropertyPersisted", PropValType_Number, True, "", 0)

Hardware and Software Requirements

 

Creating Arrays Using API - TS 2_0.seq

TestStand 2.0 or Compatible

Creating Arrays Using API - TS 2012.seq

TestStand 2012 SP1 or Compatible

 

Steps to Implement or Execute Code

  1. Open the attached sequence file
  2. Run the sequence using Run » Mainsequence.
  3. After dismissing the message box, the execution will suspend.  Click the Variables tab in the sequence editor to view the newly created variables.
  4. Resume the execution, and close the completed execution window.  Observe that the NewArraySubpropertyPersisted variable exists in your sequence.

Additional Information or References

Al B.
Staff Software Engineer - TestStand
CTA/CLD

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

Contributors