From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Example Code

Scope of LabVIEW Global Variables when using TestStand

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 the scope of LabVIEW functonal global variables when called from TestStand. 

 

Description

When calling LabVIEW code from TestStand which uses global variables, it is important to consider the scope of the variables to ensure that the code behaves as you intend.  The term 'global variable' in this document includes any of the following:

 

  • LabVIEW global variables
  • Uninitialized shift register (Functional Global Variable, or FGV)

The scope of a LabVIEW global variable is the current application instance of LabVIEW.  Each process running LabVIEW code, such as the LabVIEW Development system or the TestStand process (which can load VIs in the LabVIEW Runtime Engine) have a separate set of application instances.  Within each process, each LabVIEW project has a separate instance, as well as an additional instance for VIs not called within a project.  

 

Because of this, the following settings must match for VI calls where a global is used to share data:

 

  • LabVIEW Execution System - VIs called in the Runtime Engine are run in the TestStand process, while VIs run in the LabVIEW Development system are run out of process.  
  • Project Context - If you specify a project in a step which calls a LabVIEW module, the VI is executed in the application instance for that project

The attached example shows how the same global variable can store multiple distinct values when called in a different execution system or project context.

 

Hardware and Software Requirements

TestStand 2014 or Compatible

LabVIEW 2014 or Compatible 

 

Steps to Implement or Execute Code

  1. Extract the example files, and open the Global Scope.seq. 
  2. Run the sequence using Execute » Run Mainsequence.
  3. Observe that the same global variable is used to store different values since the steps each use a different execution system or project context.

 

Additional Information or References

For more information on LabVIEW application instances, refer to How TestStand Interacts with Application Instances.

 

Richard S -- National Instruments -- (former) Applications Engineer -- Data Acquisition with TestStand

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