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

Calling the TestStand API in Python

Code and Documents

Attachment

Overview
This code uses the Python 2.7, the pywin32 module, and the active TestStand Engine in order to create a new sequence callled "PythonSeq.seq" in the users public directory. TestStand can be called from any language that supports ActiveX calls. This can be achieved iin Python  using th Pywin32 module found here: pywin32

Note: The offically supported languages for the TestStand API are some .NET based languages, LabVIEW, and C. Calling the TestStand API in Python has not been fully tested and is not supported. This example is meant to be a starting point.

 
Description
The script uses the pywin32 module to get a reference to the TestStand engine. Once we have the engine object, we can create any of the other TestStand objects that we may need. At this point, the calls to the TestStand API will be very similar to what they would be in a .NET based language. First, a sequence file is created, then we get a reference to the MainSequence and insert a MessagePopUp step. After that, we set the value of the step, set the name and then save that sequence file to the Users Public Directory.

 
Requirements

  • Python 2.7.6
  • pywin32 Python Module
  • TestStand 2013(or later)

Steps to Implement or Execute Code

  1. Download pyscriptTS.py

  2.Run it in the Python environment of your choice

  3.Check C:\Users\Public for sequence named "PythonSeq.seq"

  4.Open that up in TestStand and verify that it has a message pop up step that says "This sequence was created from Python 2.7!"

  

Additional Information or References

 

171.png

 **This document has been updated to meet the current required format for the NI Code Exchange.**

 

Kurt P
Automated Test Software R&D

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