08-22-2024 02:10 AM
Hello forum,
I am experimenting some problems trying to send parameters to a teststand sequence via the teststand API with an external C# WPF application.
This is the way that teststand show in one example how to execute a sequence using C# and sending parameters (this is only useful calling a sequence via C# in teststand NOT in an external application):
// Create a PropertyObject with a subproperty for each parameter. Subproperties must be in the same order as parameters appear in the sequence.
PropertyObject sequenceParameters = seqContext.Engine.NewPropertyObject(PropertyValueTypes.PropValType_Container, false, "", 0);
sequenceParameters.SetValNumber("NumberVal", PropertyOptions.PropOption_InsertIfMissing, numberValue); // Use PropOption_InsertIfMissing to create the subproperty if it does not exist.
sequenceParameters.SetValString("StringVal", PropertyOptions.PropOption_InsertIfMissing, stringValue);
This way works when you call this from teststand to run teststand sequence but NOT in an external application because we don't have the sequence context.
The I tried to send it like that, but doesn't run anything, If I comment the line of setting the parameter named Port works but declaring some it's giving an error saying that the parameter doesn't exist in the sequence:
// Find the sequence file absolute path based on the calling sequence file's directory.
engine.FindFile(sequenceFileToRun, out absolutePath, out userCancelled, FindFilePromptOptions.FindFile_PromptHonorUserPreference,
FindFileSearchListOptions.FindFile_AddDirToSrchList_Ask, false);
// Locate and open the sequence file contianing the sequence to be executed.
SequenceFile targetSeqFile = engine.GetSequenceFileEx(absolutePath);
// Locate and open the process model to be used for this execution.
SequenceFile processModel = engine.GetSequenceFileEx(processModelName, GetSeqFileOptions.GetSeqFile_FindFile);
try
{
#region Get Files and Launch Execution
//Add Parameters
PropertyObject sequenceParameters = engine.NewPropertyObject(PropertyValueTypes.PropValType_Container, false, "", 0);
sequenceParameters.SetValString("Port", PropertyOptions.PropOption_InsertIfMissing, "8000");
// Launch a new execution of the sequence file using the specified process model.
// The SequenceNameParameter is the name of the process model entry point
Execution currentExecution = engine.NewExecution(targetSeqFile, sequenceNameParameter, processModel, false, 0, sequenceParameters);
#endregion
Thank you!
Solved! Go to Solution.
08-22-2024 07:58 AM
Could you please elaborate your use case a bit more?
Do you want to add parameters to a sequenc while it is running????
08-23-2024 05:38 AM
Hello Oli,
Thank you for response.
I want to add parameters before running. The case that I am experimenting is that if I don't try to load any parameter the sequence runs correctly but if I try to create a new parameter and add it the teststand doesn't give any error but doesn't work.
08-23-2024 06:09 AM
I interpret "add parameter before running" as NOT during runtime.
So before running the sequence you would have to open it via API , add parameters and save the changes. After this you'd actually run it.
Right?
08-23-2024 06:55 AM
Not exactly, because the execution starts calling a sequence and the sequences can have parameters.
I need to send the parameters just starting the sequence as a function parameters, but when I try the sequence doesn't give me any error but doesn't run.
08-26-2024 02:28 AM
Coming back to the code sample in you initial code:
You have created a ref ti the sequence file. If you want to change the parameters for a sequence within this sequence file, you need a ref to the according sequence. From there on, you should be able to add parameters.
10-07-2024 04:10 AM
public void ExecuteWithSequenceParameters(Engine engine, string sequenceFileToRun, string sequenceNameParameter, double numberValue,
string stringValue, out bool errorOccurred, out int errorCode, out String errorMsg)
{
string absolutePath;
bool userCancelled;
errorOccurred = false;
errorCode = 0;
errorMsg = String.Empty;
try
{
// Find the sequence file absolute path based on the calling sequence file's directory.
engine.FindFile(sequenceFileToRun, out absolutePath, out userCancelled, FindFilePromptOptions.FindFile_PromptHonorUserPreference,
FindFileSearchListOptions.FindFile_AddDirToSrchList_Ask, false);
// Locate and open the sequence file contianing the sequence to be executed.
SequenceFile targetSeqFile = engine.GetSequenceFileEx(absolutePath);
// Create a PropertyObject with a subproperty for each parameter. Subproperties must be in the same order as parameters appear in the sequence.
PropertyObject sequenceParameters = engine.NewPropertyObject(PropertyValueTypes.PropValType_Container, false, "", 0);
//TODO: Implement parameters
sequenceParameters.SetValNumber("NumberVal", PropertyOptions.PropOption_InsertIfMissing, numberValue); // Use PropOption_InsertIfMissing to create the subproperty if it does not exist.
sequenceParameters.SetValString("StringVal", PropertyOptions.PropOption_InsertIfMissing, stringValue);
// Launch a new execution of the sequence.
Execution currentExecution = engine.NewExecution(targetSeqFile, sequenceNameParameter, null, false, 0, sequenceParameters);
// Wait for the execution to end.
currentExecution.WaitForEndEx(-1, true, Type.Missing);
// Release the sequence file opened previously.
engine.ReleaseSequenceFileEx(targetSeqFile, 0);
}
catch (COMException e)
{
errorOccurred = true;
errorMsg = e.Message;
errorCode = e.ErrorCode;
}
}
The example function below is perfectly running a sequence in teststand sending the example "NumberVal" and "StringVal". The problem that I was experimenting is that you need to already define the sequenceNameParemeter sequence inside the sequenceFileToRun.
I created an Example.seq in teststand and inside this Example.seq I defined a subsequence entry point named SequenceWithInputParameters1
Then the entry point is setted and we will call the function below sending as a parameter sequenceFileToRun as "Example.seq" and sequenceNameParameter as "SequenceWithInputParameters1.seq" then TestStand will run "Example.seq" search for "SequenceWithInputParameters1.seq" and run the subsequence inside of the first one.
The key point is that you need to define an entry point in a sequence in order to pass parameters to it.