01-28-2019 11:09 PM
Hello Everyone
I meet one problem,I want to read the enum value from one excel file,and update it in teststand,thus I I don't need create enum data type value mannually.
I find one example to create containers with teststand API,I tried it,it works good,So I want to change it from container to enum type,but it failed.I don't know how to add elements into enum data.
anyone has an example?Thanks very much for this help.Attachment is the example to add "Container" data type.
01-29-2019 11:00 AM - last edited on 11-01-2024 04:10 PM by Content Cleaner
The files you sent were written in TestStand 2012. Enums weren't introduced into TestStand until TS 2016. Could this be the problem?
https://www.ni.com/en/support/documentation/release-notes/product.teststand.html?version=2016
Do you have a later version?
01-29-2019 07:10 PM
Hello Jiggawax
I tried this file I sent ,it can create one "Container"data type in TS2017,So i think this sequence is right ,and I tried to change the data type to "Enum",and failed ,error message is Enum data type can not use the method "setvalnum"and "setvalstring" ,And I don't know it should use which function to add into elements.
01-29-2019 07:20 PM
Hello
The change as below :
From :Locals.Type = RunState.Engine.NewDataType(PropValType_Container, False,"", 0) ,
Changeto: Locals.Type =RunState.Engine.NewDataType(PropValType_Enum, False,"", 0) ,
Original method to add elements into container:
Locals.Type.AsPropertyObject.SetValNumber("NumericField", PropOption_InsertIfMissing, 0),
Locals.Type.AsPropertyObject.SetValString("StringField", PropOption_InsertIfMissing, "")
Error Message:
The post-expression for the step 'Add FIelds to Data Type' could not be evaluated.
Error in call to TestStand API member 'PropertyObject.SetValNumber'.
You cannot create a subproperty in an item that is not a container.
Error accessing item 'NumericField'
01-30-2019 03:38 AM - last edited on 11-01-2024 04:11 PM by Content Cleaner
01-08-2024 12:04 PM
Here are the updated URLs for the links posted by @carmen9:
Enumerations as Property Objects
Enumerations in TestStand Expressions
Enum Function - to create enumeration
Additionally, the following link explains how to accomplish what the original poster was asking about using LabVIEW:
01-08-2024 12:20 PM - edited 01-08-2024 12:21 PM
Additionally, here's how to accomplish the same thing using TestStand expressions:
// Create an array of containers, where each element is a name-value pair for each value of the enum.
// The array element type, including names, must be exact, or the UpdateEnumerators( ) function will throw an exception.
Locals.NewSubProperty( "NewEnums", PropValType_Container, True,"", PropOption_DoNothingIfExists )
,Locals.NewEnums.SetNumElements( 2 /*Define the number of enum values at left*/, 0 )
// You could perform the following within a loop, but for simplicity, the two name-value pairs are defined below individually:
// Define the first name-value pair in the enum
,Locals.NewEnums.GetPropertyObjectByOffset( 0, 0 ).NewSubProperty( "EnumeratorName", PropValType_String, False, "", PropOption_DoNothingIfExists )
,Locals.NewEnums.GetPropertyObjectByOffset( 0, 0 ).NewSubProperty( "EnumeratorValue", PropValType_Number, False, "", PropOption_DoNothingIfExists )
,Locals.NewEnums[0].EnumeratorName = "Option1"
,Locals.NewEnums[0].EnumeratorValue = 1
// Define the second name-value pair in the enum
,Locals.NewEnums.GetPropertyObjectByOffset( 1, 0 ).NewSubProperty( "EnumeratorName", PropValType_String, False, "", PropOption_DoNothingIfExists )
,Locals.NewEnums.GetPropertyObjectByOffset( 1, 0 ).NewSubProperty( "EnumeratorValue", PropValType_Number, False, "", PropOption_DoNothingIfExists )
,Locals.NewEnums[1].EnumeratorName = "Option2"
,Locals.NewEnums[1].EnumeratorValue = 2
// Create a reference that will point to the new type we are about to create.
,Locals.NewSubProperty( "ReferenceToNewEnumType", PropValType_Reference, False, "", PropOption_DoNothingIfExists )
// Create the new enum type
,Locals.ReferenceToNewEnumType = RunState.Engine.NewDataType( PropValType_Enum, False, "", 0 )
,Locals.ReferenceToNewEnumType->Name = "MyEnum"
// Now, populate the values of MyEnum using values defined within Locals.NewEnums, which we initially created.
,Locals.ReferenceToNewEnumType.UpdateEnumerators( Locals.NewEnums )
// What we presently have is a new Enum type named "MyEnum" that has two values, "Option1" and "Option2"
// This type doesn't belong to the sequence file yet, so the next steps accomplish that.
// The real key to this is casting RunState.SequenceFile as a PropertyObjectFile, otherwise the TypeUsageList isn't accessible.
,RunState.SequenceFile.AsPropertyObjectFile.TypeUsageList.InsertType( Locals.ReferenceToNewEnumType, 0, TypeCategory_CustomDataTypes )
// MyEnum won't appear in the Type Editor until IncChangeCount is executed
,RunState.SequenceFile.AsPropertyObjectFile.IncChangeCount()
// Create a new local variable of type MyEnum:
,Locals.NewSubProperty( "LocalEnum", PropValType_NamedType, False, "MyEnum", PropOption_DoNothingIfExists )
// Release References
,Locals.ReferenceToNewEnumType = Nothing
// To get really fancy (optional), you could also delete the temporary local variables used to create the enum:
,Locals.DeleteSubProperty( "NewEnums", PropOption_DeleteIfExists )
,Locals.DeleteSubProperty( "ReferenceToNewEnumType", PropOption_DeleteIfExists )
// If you want to save the changes to the sequence file with the new "MyEnum" type:
,RunState.SequenceFile.AsPropertyObjectFile.SaveFileIfModified( False )
Accomplishing all of this in a single expression is not recommended, and you'd probably want to generate the values of Locals.NewEnums using a For loop, ForEach loop or step looping. But for "educational purposes" 😉 it can be done in a single expression.