Passing Data between TestStand and Python

Purpose

This example demonstrates how you can pass TestStand data types to Python code modules.

Example File Location

<TestStand Public>Examples\Fundamentals\Python\Passing Data to Python\Passing Data to Python.seq

Highlighted Features

  • Mapping of Python and TestStand types

Major API

None

Prerequisites

Complete the following steps to install the required software and configure TestStand.

  1. Install a supported version of the CPython interpreter and add it to your PATH variable.
  2. Install the following libraries for the version of Python you installed:
    • Python for Win32 (pywin32) extensions
    • NumPy module (required for the NumPy Array example)
  3. In the Python Adapter Configuration dialog box, update the Python version TestStand uses to execute Python code modules.
    Note To run the example for Enums, you must use Python 3.6 or higher.

How to Use This Example

Note The example simulates the testing of a UUT. The Model type, serial number, ports and voltage values in the example are hypothetical. The methods in the classes UUTInterface and UUTDatabase in the Python module are template methods and do not interface with any hardware or database.

Review the sequences and steps in this example. Select a subsequence in the Sequences pane to view steps in the subsequence.

Sequence Call step in the MainSequence sequence Subsequence the step calls Purpose Details
Working with Number Number Demonstrates passing numbers (integers and real) between TestStand and the Python module. The subsequence has four sections that demonstrate adding, subtracting, multiplying, and dividing two TestStand numbers in the Python module. The four sections, delineated by Label steps, use 64-bit signed integers, 64-bit unsigned integers, 64-bit double-precision floating-point number, and float and integer together respectively. An Additional Results step completes each section to provide a summary of the results.
Working with Boolean Boolean Demonstrates passing Boolean data between TestStand and the Python module. The subsequence demonstrates the inversion of the Boolean state of a TestStand variable in a Python module. An Additional Results step provides a summary of the results.
Working with String String Demonstrates passing string data between TestStand and the Python module. The subsequence demonstrates the concatenation of two TestStand strings in a Python module. An Additional Results step provides a summary of the results.
Working with List List Demonstrates passing data between TestStand arrays and Python lists. The subsequence demonstrates different operations, such as sorting and converting array data to string data, the Python module performs on TestStand array data.
Working with Tuple Tuple Demonstrates passing data between TestStand containers and Python tuples. The subsequence retrieves a single element from a TestStand container using a Python module, sets a Python attribute as a tuple using a TestStand container, and inserts a Python tuple attribute into a TestStand container.
Working with PyObject PyObject Demonstrates passing data between TestStand object references and Python objects (PyObject). The Setup step group contains the following steps:
  • The Create UUTInterface Object step and the Initialize Database step obtain the references to the instances of the Python classes that are instantiated in the Python module. TestStand stores the references in TestStand object reference variables. Steps in the Main and Cleanup step groups will use these references.

The Main step group contains the following steps:

  • The Get UUT Model Type step, which is an action step, gets the value in the static attribute of the Python class UUTInterface.
  • The Get UUT Serial Number step, which is an action step, gets the value of the attribute serialNumber from the object of the class UUTInterface, whose reference was obtained earlier.
  • The Create UUT Record in Database step, which is an action step, calls the createRecord method in the class instance object of Python class UUTDatabase, whose reference was obtained earlier.
  • The Powerup UUT step, which is an action step, calls the PowerupUUT method in the class instance object of the Python class UUTInterface whose reference was obtained earlier.
  • The UUT String Value Test step validates the serial number of the UUTInterface object.
  • The UUT Multiple Numeric Limit Test step validates the range of ports assigned to the UUTInterface object.
  • The UUT Numeric Limit Test step validates the voltage read by the UUTInterface object.
  • The UUT Pass/Fail Test step validates the test result of the UUTInterface object.
Working with Dispatch Dispatch Demonstrates passing TestStand objects and COM objects implementing IDispatch between TestStand and the Python module. The Main step group contains the following Action steps:
  • The Pass Sequence Context as Parameter step passes the SequenceContext object as a parameter to the Python code module.
  • The Pass Engine as Parameter step passes the Engine property as a parameter to the Python code module.
  • The Pass COM Object as Parameter step passes the COM object, whose reference is held in an object reference variable.

    The Pre-Expression of the step makes the object reference variable hold a reference to a PropertyObject, which is a COM object. When the step uses the object reference variable as a parameter, it passes the COM object held by the variable to the Python code module.

Working with Enum Enum Demonstrates passing enumerations between TestStand and the Python module. The Main step group contains the following Action steps:
  • The Pass Enum Color step passes the TestStand enum as a Python enum parameter with a type of Enum to the Python code module.
  • The Pass Flag Measurement step passes the TestStand enum as a Python enum parameter with a type of Flag to the Python code module.
  • The Pass IntEnum FileOpenOption step passes the TestStand enum as a Python enum parameter with a type of IntEnum to the Python code module.
  • The Pass IntFlag FilePermission step passes the TestStand enum as a Python enum parameter with a type of IntFlag to the Python code module.
Working with NumPy Array NumPy Array Demonstrates passing data between a TestStand array and a Python NumPy array. The subsequence demonstrates passing TestStand arrays to a Python module and performing a sorting operation using NumPy arrays.

Complete the following steps to run the example.

  1. Click Execute»Single Pass to run the sequence.
  2. When execution completes, review the report.