11-28-2022 07:47 AM - edited 11-28-2022 07:48 AM
Hello,
I need to execute a sequence through a C# .net app.
I looked at the National Instruments example "Executing Sequences Using API" in .net, and would like to use the given (see below) ExecuteWithNoProcessModel method.
My problem is, this method is not used in a Main program in this example, there only is a .cs file, so I do not understand how to call this function.
Can somebody explain to me how to get a SequenceContext ? I guess I should call here the current sequence context, I found the method UIMessage.Thread.GetSequenceContext, but I do not understand how to use it.
Thank you for your help.
Here's is the example code I'd like to use :
public void ExecuteWithNoProcessModel(SequenceContext seqContext, string sequenceFileToRun, string sequenceNameParameter,
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.
seqContext.Engine.FindFile(sequenceFileToRun, out absolutePath, out userCancelled, FindFilePromptOptions.FindFile_PromptHonorUserPreference,
FindFileSearchListOptions.FindFile_AddDirToSrchList_No, false, seqContext.SequenceFile);
// Locate and open the sequence file contianing the sequence to be executed.
SequenceFile targetSeqFile = seqContext.Engine.GetSequenceFileEx(absolutePath);
// Launch a new execution of the sequence.
Execution currentExecution = seqContext.Engine.NewExecution(targetSeqFile, sequenceNameParameter, null, false, 0);
// Wait for the execution to end.
currentExecution.WaitForEndEx(-1, true, Type.Missing, seqContext);
// Release the sequence file opened previously.
seqContext.Engine.ReleaseSequenceFileEx(targetSeqFile, 0);}
Solved! Go to Solution.
11-28-2022 09:43 AM
Hello IsMu,
I'm a little unsure about the scope of that example. Because a SequenceContext only exists when an Execution is already running.
If you simply want to execute a single TS sequence, all you need should be:
1. Get the TestStand Engine using the ApplicationManager.GetEngine() Method
2. Get the Sequence File using the Engine.GetSequenceFileEx() Method
3. Run the a sequence from that sequence file using the Engine.NewExecution() method
4. Clean up correctly afterwards.
It is basically what the ExecuteWithNoProcessModel method below does, except it gets a reference to the Engine from the ApplicationManager instead of a SequenceContext (which does not exist in this context).
I'd personally recommend taking a look at the CSharp UserInterfaces examples that ship with teststand to get an idea how to handle a TestStand instance in your c# app.
11-29-2022 02:54 AM
Thank you very much for your help ! Now it worked.
01-12-2023 07:51 AM
Hello ,
Please how to get sequence context in orders to have access to :
- Locals
-Parameters
-FileGlobals
-Stations Globals
-This Context
-RunSatte
I know that we can get it by calling dll from testStand but it's not my need , what I m' looking for is to get thisContext from API Dotnet
Her my source code :
EngineClass myEngine = new EngineClass();
SequenceFile mySequenceFile = myEngine.GetSequenceFileEx(MySeqPath, 0, TypeConflictHandlerTypes.ConflictHandler_Prompt);
SequenceFile MyModule = myEngine.GetSequenceFileEx(MyModulPath, GetSeqFileOptions.GetSeqFile_NoOptions, TypeConflictHandlerTypes.ConflictHandler_Error);
Execution NewRun = myEngine.NewExecution(mySequenceFile, "Single Pass", MyModule, false, 0);
Thread FirstThread_ = NewRun.GetThread(0);
SequenceContext seqContext = FirstThread.GetSequenceContext(0, out frameId);
PropertyObject propertyObjContext = seqContext .AsPropertyObject();
double var_1 = GetValNumber("Locals.Var_2", 0);
double var_1 = GetValNumber("Parameters.Var_3", 0);
double var_1 = GetValNumber("FilesGlobals.Var_2", 0);
double var_1 = GetValNumber("StationsGlobals.Var_4", 0);
double var_1 = GetValNumber("RunState.Var_5", 0);
double var_1 = GetValNumber("ThisContext.StationGlobals.contVar_1", 0);
double var_1 = GetValNumber("ThisContext.RunState.contVar_2", 0);
The idea it to be able to have acces to all variables , I see on the documentation that is possible with using SequenceContext , but I don't know how to get this context , it doesn'tt work from my side
My project is to do HIM in c# and sequences in Teststand , so My HMI mus be able to retrieve values states name of test tolerance MinMAx ....
Thank you for your helps
01-12-2023 08:32 AM - edited 01-12-2023 08:33 AM
If you have an Execution object then you can use GetThread method to get a thread. Having a thread object you can use GetSequenceContext method to get a context. You can access context variables using object (class) properties or use GetVal method (after casting to PropertyObject class).
01-12-2023 10:28 AM
Hello Bienieck,
Thank you very much for replying to me , unfortunately what you described is exactly what I did , just my previous mail contains some bad copy pass from my project , but the mechanism is exactly the same.
Please here my code :
and when I run the sequence all the things is Ok until first,GetvalueNumber here the exception that I have from Visual studio :
here my workspace of my . seq file
thank you again for your help
01-12-2023 02:36 PM - edited 01-12-2023 02:49 PM
Try seqContext.Locals.GetValNumber("Val_1",0) or propertyObjectContext.GetValNumber("Locals.Var_1",0). Both worked in SeqEdit when I tried it. However, I'm not sure how it will work in Visual Studio in edit-time. Normally the context is created at run-time so it is normal to see expression evaluation errors when working with it. In SeqEdit the edit-time context is kind of approximation of what is expected in run-time. Idk if you will get this experience in VS.
01-13-2023 03:44 AM
Hello Mr Bienienck,
I tried again with this ways as you mentioned but unfortunately it's doesn't work , same error
but when I use the Sequencefile it's work to get just Local and parameters Variables , but it's not my need , that why I look for Context : like that I will have access to the ALL
what do you think please