NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

C# .net Get current SequenceContext

Solved!
Go to solution

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);}

0 Kudos
Message 1 of 8
(5,544 Views)
Solution
Accepted by topic author IsMu

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.

Message 2 of 8
(5,519 Views)

Thank you very much for your help ! Now it worked.

0 Kudos
Message 3 of 8
(5,367 Views)

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  

T_RIDA_0-1673531231432.png

 

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  

 

0 Kudos
Message 4 of 8
(5,160 Views)

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).

Michał Bieńkowski
CLA, CTA, CPI

  1. Did someone devote their time to help solve your problem? Appreciate it and give kudos.
  2. Problem solved? Accept as a solution so that others can find it faster in the future.
  3. Contribute to the development of TestStand by voting on the TestStand Idea Exchange.
0 Kudos
Message 5 of 8
(5,149 Views)

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  : 

T_RIDA_2-1673540716840.png

 

and when I run the sequence all the things is Ok until first,GetvalueNumber here the exception that I have from Visual studio  :   

T_RIDA_3-1673540772095.png

 

here my workspace of my . seq file 

 

T_RIDA_4-1673540874635.png

 

thank you again for your help  

 

 

 

0 Kudos
Message 6 of 8
(5,130 Views)

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.

Michał Bieńkowski
CLA, CTA, CPI

  1. Did someone devote their time to help solve your problem? Appreciate it and give kudos.
  2. Problem solved? Accept as a solution so that others can find it faster in the future.
  3. Contribute to the development of TestStand by voting on the TestStand Idea Exchange.
0 Kudos
Message 7 of 8
(5,120 Views)

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  

 

T_RIDA_0-1673602846717.png

what do you think  please 

 

  

0 Kudos
Message 8 of 8
(5,081 Views)