From Saturday, Nov 23rd 7:00 PM CST - Sunday, Nov 24th 7:45 AM CST, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Saturday, Nov 23rd 7:00 PM CST - Sunday, Nov 24th 7:45 AM CST, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
In LabVIEW, it is possible to create multiple application instances within the same LabVIEW process, which each act like a separate instance of LabVIEW. This feature has many benefits, but can also cause unexpected behavior if not considered when developing your test code. When calling LabVIEW code from TestStand, or using a LabVIEW built TestStand User Interface, it is important to consider how LabVIEW application instances will affect the execution of your test. This document provides information on these considerations, and discusses the best approach for common scenarios.
This section provides an overview of the behavior of application instances in LabVIEW. It is important to understand this behavior before investigating how it effects a TestStand system.
Within the LabVIEW process, you can create independent instances of the environment, known as application instances. LabVIEW creates an application instance for each target within the project. By default, a LabVIEW project contains a single "My Computer" target. LabVIEW also creates a Main application instance, which contains VIs not in a LabVIEW Project.
When working in LabVIEW, you can use the application instance name that appears in the application instance shortcut menu on the bottom left corner of the front panel and block diagram windows to identify which application instance a VI belongs to. In addition, this control allows you to change the application instance of the VI to any other available instance. Note that this does not cause the VI to be removed from the LabVIEW project, it only changes the instance in which the VI is loaded in memory.
You can open the same VI on disk in multiple application instances at the same time. Each application instance behaves as a separate instance of LabVIEW. For example, you can open the same VI on disk in two different projects.
Each VI instance can be used independently, and maintains independent copies of the following items:
This means that Global and functional variables cannot be used to share data between VIs in different application instances. VIs can only communicate across application instances using methods such as:
When you create an executable from LabVIEW, the executable runs within it's own process in the operating system. As with the Development Environment, LabVIEW executables can contain multiple application instances. In most cases, all VIs in an executable use the main application instance, but any shared libraries (for example LabVIEW built DLLs or .NET Interop assemblies) will execute in their own application instance. Additional application instances can be created for other reasons as well. Some of these cases are explored later in the document.
The diagram below illustrates the hierarchy of Operating system » LabVIEW process » Application Instance
In some cases, it is necessary to run VIs that are built with two different LabVIEW versions in the same process. For example, a TestStand sequence can call both LabVIEW 2009 and LabVIEW 2012 VIs. In order to execute VIs in different LabVIEW versions, a LabVIEW Run-Time Engine module for each LabVIEW version must be loaded into the current process. Each of these LabVIEW Run-Time Engine modules, like the LabVIEW development system, contain a Main application instance, and can contain additional application instances for shared libraries.
Note: In the previous sections, the module layer was not discussed to avoid unnecessary complexity. A process using LabVIEW typically only contains a single LabVIEW module, so it does not have an effect on functionality unless a single process is using multiple LabVIEW versions.
In the case that VIs in both Main Application instances call into a shared dependency, such as a shared library, a new application instance is created for each Main application instance. The diagram below illustrates this organization within the LabVIEW process.
In this section, we explore how LabVIEW application instances can effect the various forms of TestStand and LabVIEW interaction.
When using TestStand to interact with LabVIEW, it is important to consider the application instance that the VI code modules will execute in. The amount of control provided in TestStand varies based on the TestStand version being used and the current LabVIEW execution system (specified in the LabVIEW adapter settings). The differences are summarized in the table below.
Development system adapter setting | Run-time engine adapter setting | |
TestStand 4.2.1 and previous | all VIs are called in the main LabVIEW application instance of the LabVIEW process. | All VIs are called in the main application instance of the LabVIEW Run-Time Engine module loaded by the TestStand process*. If steps are configured to use different LabVIEW runtime engine versions, a Main application instance is created for each LabVIEW Run-Time Engine version used. |
TestStand 2010 and later | By default, all VIs are called in the main application instance of the LabVIEW process. You can optionally select a LabVIEW project in the module tab in addition to selecting a VI. In this case, the VI will execute in the application instance of the "My Computer" target within the selected project in the LabVIEW process. If you specify a project for any VIs, make sure that you call any VIs that need to share data using global variables are called within the same application instance. | By default, all VIs are called in the main application instance of the LabVIEW Run-Time Engine module loaded by the TestStand process*. You can optionally select a LabVIEW project in the module tab in addition to selecting a VI. In this case, the VI will execute within the application instance of the the "My Computer" target selected project in the TestStand process. If steps are configured to use different LabVIEW runtime engine versions, a Main application instance is created for each LabVIEW Run-TIme Engine version used. |
*The TestStand process refers to the process of the executable using the TestStand engine, which is typically the sequence editor or TestStand user interface.
When running sequences using the sequence editor, the application instance used to execute VIs typically does not have any effect on functionality. However, issues can arise when using calling LabVIEW code modules in conjunction with using a LabVIEW built TestStand user interface, as described in the next section.
A LabVIEW built TestStand user interface behaves like any other LabVIEW application in regards to application instance behavior. The table below summarizes the behavior.
Type of User Interface | Behavior |
User Interface as a VI | User Interface VIs are executed in the application of the containing project (the Build Script.lvproj project, in the case of the example user interfaces included with TestStand). If you load the user interface VI or LLB without using a project, it will execute in the main application instance. |
User Interface as an EXE | User Interface VIs execute in the run-time application instance in the executable's process |
When using the LabVIEW user interface to execute sequences which call LabVIEW code modules, many variables are involved in determining the application instance behavior:
It is very important to understand what application instances are used in each case, because behavior changes can occur when changing these settings, such as:
These settings are typically changed when preparing a TestStand system for deployment, especially the User Interface application type and the VI execution system settings. The table below explores what behavior you will encounter when changing these settings, assuming all VIs are built using the same LabVIEW version. The next section describes methods to address the issues that can arise due to these changes.
Development system adapter setting | Run-time engine adapter setting | |
Executing User Interface as a VI in LabVIEW | This is the typical configuration on a TestStand development system. All user interface VIs will execute in the UI project application instance, or the main application instance if no project is used. All code module VIs will execute in the specified project instance. If no project is specified for a VI code module, it executes in the main application instance. All VIs will be executed in the LabVIEW process. in this case, if no user interface project is used, user interface VIs and code module VIs with no project specified will run in the same application instance. | This is the typical configuration on a TestStand development system when conducting deployment testing. All user interface VIs will execute in the UI project instance, or the main application instance of the if no project is used. All code module VIs will execute in the specified project instance. If no project is specified for a VI code module, it executes in the main application instance. All VIs will be executed in the LabVIEW process. in this case, if no user interface project is used, user interface VIs and code module VIs with no project specified will run in the same application instance. |
Executing User Interface as a Stand-alone EXE | This configuration is not typical. In some cases, this set up may be used if VIs are executed using the LabVIEW development environment on a deployed system, which is typically not recommended. User Interface VIs execute in the run-time application instance in the User Interface executable's process. All code module VIs will execute in the specified project instance in the LabVIEW process. If no project is specified for a VI code module, it executes in the main application instance of the LabVIEW process in this case, user interface VIs and code module VIs always execute in a different process. | This is the typical configuration on a deployed TestStand system. User Interface VIs execute in the run-time application instance of the LabVIEW Run-time engine loaded by the executable's process. All code module VIs will execute in the specified project instance in the LabVIEW Run-time engine loaded by the User Interface executable process. If no project is specified for a VI code module, it executes in the main application instance of the LabVIEW Run-time engine loaded by User Interface executable process. in this case, user interface VIs and code module VIs with no project specified will run in the same application instance. All VIs will run in the LabVIEW Run-time engine loaded by User Interface executable process. |
In the case that code module VIs are not built in the same LabVIEW version as the user interface, these code module VIs will execute in a new main application instance, contained within the corresponding LabVIEW run-time engine version module.
Refer to the Using multiple LabVIEW Run-time engines in a single process section above for more information.
Note: this behavior does not occur when using the development system execution system for a code module, since all code module VIs are recompiled into the current LabVIEW version before execution.
This section addresses issues that can occur due to problems with the way Application Instances are used in a TestStand application. In many cases, these issues occur when deploying a TestStand system, since many of the settings affecting the application instance behavior are modified at this time.
If changes to your system cause VIs to no longer execute in the same application instance, sharing data between the VIs using global or functional global variables will no longer work, since each VI is accessing a separate instance of the variable. This can occur for a few reasons, including:
In the case that you are sharing data between the user interface and code modules using globals, you should consider using TestStand User Interface messages, or UI Messages. This method allows you to communicate between the TestStand sequence and user interface without the need for any shared dependencies such as global variables, in addition to other benefits. for more information on effectively using UI Messages, refer to this article:
Using TestStand User Interface Messages (UI Messages)
In the case that you are sharing data between code modules, you should typically configure the modules to use the same project in the module settings for the step. This will ensure that these code modules are executed in the same application instance.
In many test applications, multiple code modules use the same reference to hardware, such as a NI-DAQ task or a VISA session to communicate with hardware. It is important to understand how LabVIEW stores these references and when they are valid to avoid invalid reference issues.
When a hardware reference is opened in LabVIEW, the driver module creates the reference and provides a reference number (refnum) to LabVIEW. Because the LabVIEW process has a single instance of the driver module, a hardware reference will be valid in any application instance within the LabVIEW process. However, if you use a global or functional global to store the hardware reference, the reference value will be invalid if you attempt to share it between multiple application instances. For this reason, you consider storing hardware references into a TestStand property, which you can pass in as a parameter to any VIs which access the hardware.
Issues can arise in scenarios such as:
If changes to your system cause VIs to execute in the same application instance, but previously executed in separate application instances, you may encounter naming conflicts. This can occur because two VIs of the same name can be loaded simultaneously if they are in different application instances, but only one instance can be open within a single application instance. This issue can occur in scenarios such as:
To address these issues, consider using unique names for all VIs to avoid naming conflicts. Also, you should avoid having multiple copies of your VIs on disk to prevent cross linking.