Example Code

Creating a Persistent Variable 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

Description

Overview

This example demonstrates how you can use the TestStand API to create new variables in your sequence file which persist at edit-time. 

 

Description

You can create variables in a sequence using the Runstate.Sequence object in the TestStand API.  However, since this sequence object refers to the running copy of the sequence, and changes or new properties are only persisted for the active execution.  

 

To access the edit-copy of the sequence file, you must access the sequence from the sequence file object in one of two ways:

 

  • Runstate.SequenceFile - Use this approach to access the currently running sequence file.
  • Runstate.Engine.GetSequenceFileEx("mySequenceFile.seq") - Use this approach to access a different sequence file.

Once you have obtained the sequence file object, complete these steps to make a modification:

 

  1. Access the desired property.  For a local variable in the main sequence, Use Runstate.SequenceFile.GetSequenceByName("MainSequence").Locals.
  2. Modify or create new properties using the SetVal methods, for example SetValString.
  3. Increment the change count of the sequence file using SequenceFile.IncChangeCount() to indicate that it has been modified.
  4. Save the file if desired using SequenceFile.Save().
  5. If you obtained the sequence file using Engine.GetSequenceFileEx(), you must release it using Engine.ReleaseSequenceFileEx().

 

Hardware and Software Requirements

Add Persistant Variable to Sequence File - TS2012.seq 

TestStand 2012 or compatible

 

Add Persistant Variable to Sequence File - TS2019.zip (seq)

TestStand 2019 or compatible

 

Steps to Implement or Execute Code

  1. Open the attached sequence file, and select Execute » Run MainSequence.
  2.  When prompted, choose whether to use the current sequence file or another file.  
  3. If you choose to use another file, the browse dialog appears.  Select a sequence file.
  4. Once the execution completes, observe that the file you chose has a new local variable called "Locals.myNewVar".
  5. If the sequence file you modified was already open, observe that the file is marked as modified due to the call to IncChangeCount().

 

 

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