NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Set and send parameters to a teststand sequence via an external C# WPF application

Solved!
Go to solution

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!

0 Kudos
Message 1 of 7
(374 Views)

Could you please elaborate your use case a bit more?

Do you want to add parameters to a sequenc while it is running????

0 Kudos
Message 2 of 7
(349 Views)

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.

 

0 Kudos
Message 3 of 7
(336 Views)

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?

 

 

 

0 Kudos
Message 4 of 7
(333 Views)

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.

0 Kudos
Message 5 of 7
(326 Views)

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.

0 Kudos
Message 6 of 7
(303 Views)
Solution
Accepted by topic author electricdami
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

 

electricdami_0-1728291954751.png

 

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.

 

0 Kudos
Message 7 of 7
(76 Views)