Run VI Asynchronously in TestStand

Updated Oct 18, 2022

Environment

Software

  • TestStand
  • LabVIEW

To run a portion of code asynchronously when developing an application is a common need. In this article, we will be sharing how to run a LabVIEW VI asynchronously in your TestStand sequence file. Execution of asynchronous LabVIEW VI will also be visualized for the purpose of monitoring as well as to improve your understanding of this topic.

The steps below include preparations that have been done on both LabVIEW and TestStand from scratch.

LabVIEW
  1. Create an empty LabVIEW VI.
  2. In the front panel, place an Automation Refnum control from Controls Palette»Refnum»Automation Refnum. 
    automation refnum
  3. Right-click on the Automation Refnum and select Select ActiveX Class»Browse. A Select Object From Type Library dialog box will appear. 
    select
  4. Within the Select Object From Type Library dialog box, select NI TestStand <Year> API Version x.0 as value for Type Library dropdown.
    teststand API
  5. Select SequenceContext from the Objects listbox and click OK.
    object listbox
  6. It can be observed that the name of Automation Refnum is now TS.SequenceContext.
  7. Click the upper left square box of the connector pane and click TS.SequenceContext. The upper left square box of the connector pane should now be green in color.  
    connector pane
  8. Place TestStand - Initialize Termination Monitor.vi, TestStand - Get Termination Monitor Status.vi and TestStand - Close Termination Monitor.vi into the block diagram from Functions Palette»TestStand. 
    teststand
  9. Interconnect TestStand - Initialize Termination Monitor.vi, TestStand - Get Termination Monitor Status.vi and TestStand - Close Termination Monitor.vi.
  10. Connect TS.SequenceContext to the Sequence Context In input of TestStand - Initialize Termination Monitor.vi.
  11. Surround TestStand - Get Termination Monitor Status.vi with a while loop and connect its Terminating and Aborting output to termination terminal of the while loop.
  12. Within the while loop, create an indicator for the iteration terminal and place a 100 ms of delay using Wait(ms).
  13. Image below illustrates the block diagram at this stage. 
    blockdiagram 
    Note: 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.
  14. Press <Ctrl-I>, select Window Appearance in the Category dropdown and select Dialog.
    vi properties
  15. Save the VI. It will be called in TestStand later.

TestStand
  1. From Insertion Palette >> LabVIEW Utility, drag and drop Run VI Asynchronously into your Steps. 
    teststand step
  2. Select the inserted Run VI Asynchronously in the Steps pane. Step Setting pane of Run VI Asynchronously will be shown. 
    highlight
  3. In Remote System, fill in the hostname and port number of the remote system's VI Server accordingly. As this article is using LabVIEW installed on the local computer, both hostname and port are leave default. 
    remote server
  4. Select Use Context of Calling Thread for Context to Pass as ThisContext for VI Arguments
    thiscontext
  5. Click the L icon to specify which VI to call. 
    specify VI
  6. In the Edit LabVIEW VI Call dialog box, click Browse for VI and select the VI created in LabVIEW section of this article. 
    specify vi
  7. After specify the VI, un-check the Default box for the TS.SequenceContext parameter and set the Value to ThisContext. Press OK.
    value
With the above implementations, when you run the sequence file, you will now be able to see the LabVIEW VI is started and running while TestStand is proceeding to the next step without waiting the VI finish executing.