Using the TestStand API in LabVIEW

Updated Apr 7, 2023

Environment

Software

  • LabVIEW
  • TestStand

This document provides an overview of creating a LabVIEW code module with access to the TestStand API, and demonstrates how to access API properties and methods in LabVIEW. Refer to Using the NI TestStand Object Model for more information on the structure of TestStand objects and the TestStand API.

Creating a Code Module with Access to the TestStand API in LabVIEW

 

Follow the steps below to create a new LabVIEW code module with access to the TestStand API. You must have the LabVIEW development system active in the LabVIEW adapter settings to use this approach.

  1. To create a new VI from a template, select the Create VI button in the module tab of the step, as shown.
     


 
  1. After specifying a name and location for the new VI, the VI will be generated using the template below. TestStand uses a specific template depending on the step type you use. For example, a numeric limit test step contains an additional numeric measurement output.
     

 
  1. To access the active sequence context in the code module, you must provide a reference to this context in TestStand.  To do so, pass ThisContext to the code module from TestStand, as shown below:
 

 

The SequenceContext (or ThisContext) object contains a snapshot of the current state of TestStand execution, including references to the current sequence file, sequence, step, execution, and thread. The SequenceContext also provides access to the TestStand engine. In most cases, the code module can access all information it needs using the SequenceContext.
 

Programming with the TestStand API in LabVIEW

 

To use the TestStand API in the new VI, use property nodes and invoke nodes to access built-in properties and methods, respectively. You can access this quickly in the context menu for the Sequence Context reference, as shown:

 


For example, the code below accesses the name property of the current sequence (the sequence where we called the LabVIEW module).

To prevent memory leaks, always call the Close Reference VI  on any object that is returned from a property or invoke node once you are finished using it.  Do not close references that are passed into the VI, such as the SequenceContext.

Equivalent expression: ThisContext.Sequence.Name = "newName"
 

Unlike the expression browser, you cannot access dynamic properties, i.e. objects contained within the current object, directly through a property node. For example, there is no Main API property for the sequence class; Main is a dynamic PropertyObject contained by the sequence object. To access the dynamic PropertyObjects contained by the current object, you have two options:
 

  • Use the GetPropertyObject method to access a contained property. This method uses a lookup string to specify the location of the object using dot syntax. Since this is a method of the PropertyObject class, you first need to use the AsPropertyObject method to cast the sequence object to a PropertyObject. In the example below, we use this approach to access a particular step. 
     

    Equivalent expression: ThisContext.Sequence.Main["Action"].Name = "newStepName" 
     

  • If available, use a method supplied in the API to get the sub-object. For the example of accessing a step name, you can call the GetStepByName  method to directly access the step object. 

    Equivalent expression: ThisContext.Sequence.GetStepByName("Action",StepGroup_Main).Name = "newStepName" 


For more information, refer to the following TestStand help topics:


Refer to the following topics for advanced topics on using the TestStand API in LabVIEW:

 

Accessing TestStand API Help from LabVIEW

 

You can access documentation on the properties and methods of the TestStand API using the context help window.  You can access the full API documentation for the selected property or method by clicking the "?" icon in the Context Help window.