You can accomplish this by using the Run VI Asynchronously
step type in TestStand. This will run the VI in a new thread, allowing your TestStand sequence to continue past that step. To call a VI asynchronously, follow the steps below.
First, you must prepare your VI to be started and stopped by TestStand in LabVIEW.
- On your VI's Front Panel, place an Automation Refnum control from
Controls Palette»Refnum»Automation Refnum.
- Next, right-click on the Automation Refnum and choose
Select ActiveX Class»Browse...
- In the Select Object From Type Library window, find and select NI TestStand <year> API Version x.0 from the Type Library drop-down menu.
- In the Objects window, select SequenceContext. Select OK. The Automation Refnum should now read
- Switch to the Block Diagram. Create a property reference to the parameters in TestStand by right-clicking on the Sequence Context Refnum control and selecting
Create»Property for TS.SequenceContext Class»Parameters.
- Right-click on the Parameters node in the SequenceContext Property Node, and select
Create»Method for TS.PropertyObject Class»GetValBoolean.
- Place the SequenceContext Property Node and the PropertyObject Invoke Node inside the loop you will be dynamically stopping from TestStand to stop the VI.
- Wire the Sequence Context Refnum into the SequenceContext Property Node, and wire the reference from Parameters into the PropertyObject Invoke Node.
- Specify the parameter name and wire the Boolean value from GetValBoolean to the conditional terminal of the loop.
- Save the VI.
: This image is a LabVIEW snippet, which includes LabVIEW code that you can reuse in your project. To use a
snippet, right-click the image, save it to your computer, and drag the file onto your LabVIEW diagram
Next, you need to configure TestStand to call your modified VI asynchronously.
- Add a Run VI Asynchronously step into your sequence. This step can be found in the Insertion Palette in the LabVIEW Utility folder.
- In the Step Settings pane, leave the Hostname blank so that TestStand will default to the local host, and click on the LabVIEW icon.
- In the Edit LabVIEW VI Call window, enter the path of the VI you want to run, either manually or using the file explorer button.
- After the VI has been properly loaded, un-check the Default box for the TS.SequenceContext parameter and set the Value to
ThisContext. Press OK.
- In the Variables pane, add a new Boolean parameter under the Parameters section named the same as the lookupString value you defined in LabVIEW (see above), and set the default value to
- In the Run VI Asynchronously Step Settings pane, select the Context to Pass as This Context for VI Arguments as Use Context of Calling Thread.
- To stop the VI, add a Statement step, and in the Expression box, enter
Parameters.Stop = True.
This method causes TestStand to execute the VI in a new thread, and uses a Parameter (named Stop
in the example above) which your VI will access and read through the Sequence Context passed into it from TestStand.
Additionally, when running asynchronous code in general, you can use the termination monitor
to ensure that your VI stops if the TestStand execution is terminated or aborted by the user.
Due to multi-threading and the parallel nature of this method, you must take care to prevent or mitigate race conditions. Passing data to and from asynchronous VIs using this method is discouraged. This method should only be used to start and stop VIs that have no other data dependencies. Data transfer between asynchronously called VIs should be handled through Queues, Notifiers, or UI Messages in the related links.