Example Programs

cancel
Showing results for 
Search instead for 
Did you mean: 

Using the TestStand API to create a Data Type

Overview

 This example demonstrates how you can use the TestStand API to:

  • Create a new data type.
  • Add fields to the type.
  • Add the data type to the type usage list of a sequence file.
  • Configure struct and cluster passing settings.
  • Create an instance of the data type in a sequence file.

Description

If you are not familiar with TestStand data types, refer to NI TestStand Type Management Best Practices for more information before using this example.

 

This example uses the TestStand API to create a new data type, and create an instance of the type in a sequence file:

 

  1. Obtain a reference to the sequence file which will contain the type.

    Locals.SequenceFile = RunState.Engine.GetSequenceFileEx("", 107, ConflictHandler_UseGlobalType)
  2. Check if the desired type name is already loaded in memory before attempting to create the type.  If the type does not exist, the output is NULL.

    Locals.Type = RunState.Engine.GetTypeDefinition(Parameters.TypeName)
  3. If the type does not exist (Locals.type in NULL), create it, and add it to the sequence file's type usage list (the list of types stored with the sequence file).

    Locals.Type = RunState.Engine.NewDataType(PropValType_Container, False,"", 0)
    Locals.SequenceFile.AsPropertyObjectFile.TypeUsageList.InsertType(Locals.Type, 0, TypeCategory_CustomDataTypes)
  4. Set the name of the data type, and add fields to the data type using the PropertyObject API.

    Locals.Type.AsPropertyObject.Name = Parameters.TypeName,
    Locals.Type.AsPropertyObject.SetValNumber("NumericField", PropOption_InsertIfMissing, 0),
    Locals.Type.AsPropertyObject.SetValString("StringField", PropOption_InsertIfMissing, "")
    
  5. Enable Cluster and Struct passing, which allows passing instances of the type to LabVIEW and DLL code modules.

    RunState.Engine.GetAdapterByKeyName(FlexCAdapterKeyName).AsCommonCAdapter.SetAllowStructPassing(Locals.Type, True),
    RunState.Engine.GetAdapterByKeyName(FlexLVAdapterKeyName).AsLabVIEWAdapter.SetClusterPassingEnabled(Locals.Type, True)
  6. Create a new instance of the data type in the MainSequence Locals.

    Locals.SequenceFile.AsSequenceFile.GetSequenceByName("MainSequence").Locals.NewSubProperty("instance", PropValType_NamedType, False, Parameters.TypeName, 0)
  7. Increment the change count to indicate that the sequence file has been modified.

    Locals.SequenceFile.AsSequenceFile.IncChangeCount()
  8. Save the sequence file and release the reference.

    Locals.SequenceFile.AsPropertyObjectFile.SaveFileIfModified(False),
    RunState.Engine.ReleaseSequenceFileEx(Locals.SequenceFile, 0)

 

Hardware and Software Requirements

Create Data Type Using TestStand API.zip

TestStand 2012 or Compatible 

 

Steps to Implement or Execute Code

  1. Extract the attached archive, and open Create Data Type Using TestStand API.seq.
  2. Run the sequence using Execute » Run Mainsequence.
  3. When prompted, select the TargetSequenceFile.seq.
  4. After the execution completes, open TargetSequenceFile.seq in the sequence editor.  Press Ctrl + T to open the types pane.  Observe that a new type is present under Custom Data Types in the sequence file.

    2018-04-06_150023.png

  5. select the TargetSequenceFile.seq tab.  Observe that an instance of the type is generated in the MainSequence local variables.

 

Additional Information or References

  NI TestStand Type Management Best Practices 

Al B.
Staff Software Engineer - TestStand
CTA/CLD
Contributors