Method 1: Using TestStand API Calls in a Statement Step
- Open the sequence file in TestStand.
- Add a Statement step to retrieve the current User type version:
Locals.CurrentVersion = RunState.Engine.UsersFile.AsPropertyObjectFile().TypeUsageList.GetTypeDefinition(0).TypeVersion
- Split the version string into its individual components:
Locals.Parts = Split(Locals.CurrentVersion, ".")
- Create a new version string by incrementing the final version component:
Locals.NewVersion = Locals.Parts[0] + "." + Locals.Parts[1] + "." + Locals.Parts[2] + "." + Str(Val(Locals.Parts[3]) + 1)
- Assign the updated version value to the User type definition:
RunState.Engine.UsersFile.AsPropertyObjectFile().TypeUsageList.GetTypeDefinition(0).TypeVersion = Locals.NewVersion
- Mark the file as modified:
RunState.Engine.UsersFile.AsPropertyObjectFile().IncChangeCount()
- Save the updated Users.ini file:
RunState.Engine.UsersFile.AsPropertyObjectFile().SaveFileIfModified(False)
- If you only need to read the currently loaded User type version without modifying the file, use:
RunState.Engine.GetTypeDefinition("User").TypeVersion
Method 2: Using a .NET Code Module
- Create a .NET Class Library project and add references to the TestStand Interop assemblies.
- Create a public method that accepts a SequenceContext parameter.
- Add code similar to the following example:
using System;
using NationalInstruments.TestStand.Interop.API;
namespace TestStandUserVersionTest
{
public class UserVersionHelper
{
public static string IncrementUserTypeVersion(SequenceContext seqContext)
{
Engine engine = seqContext.Engine;
UsersFile usersFile = engine.UsersFile;
PropertyObjectFile usersPof = usersFile.AsPropertyObjectFile();
TypeUsageList typeUsageList = usersPof.TypeUsageList;
PropertyObject userType = typeUsageList.GetTypeDefinition(0);
string currentVersion = userType.TypeVersion;
string[] parts = currentVersion.Split('.');
if (parts.Length != 4)
{
throw new Exception(
"Unexpected TypeVersion format: " + currentVersion);
}
parts[3] = (int.Parse(parts[3]) + 1).ToString();
string newVersion = string.Join(".", parts);
userType.TypeVersion = newVersion;
usersPof.IncChangeCount();
usersPof.SaveFileIfModified(false);
return $"Updated User TypeVersion from {currentVersion} to {newVersion}";
}
}
}
- Build the assembly.
- Add an Action step in TestStand and configure it to call the .NET method.
- Pass ThisContext to the SequenceContext parameter.
- Execute the sequence and verify that the returned message reports the original and updated version values.