NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Run sequence in .nET by Teststand API

Solved!
Go to solution

Hello,

 

I am looking for a simple way to start sequence file in the background in .NET.

Based on what I found in the documentation following code should work:

 

 

        Engine engine = new Engine();
        engine.UIMessageEvent += msg =>
        {
            var events = msg.Event;
        };
        var sequence = engine.GetSequenceFileEx(@"C:\MyNiceSequence.seq");
        sequence.LoadModules(0, null);
        var execution = engine.NewExecution(sequence, "MainSequence", null, false, 0x1);       
        execution.WaitForEnd((int) TimeSpan.FromMinutes(1).TotalMilliseconds, false, null);

 

 

This sequence loads some .net modules if this is relevant.

No callbacks are sent by teststand

It seems like sequence keeps running forever, Can I somehow check on what step it is stuck?

0 Kudos
Message 1 of 6
(1,065 Views)

Hey, brother:

        I found that your code is missing steps.

 

        If you want to use TS API to receive UI messages during seq operation, you need to do the following:

 

              1. After you instantiate the engine, Inform the engine that you are polling by setting the Engine.UIMessagePollingEnabled property to True. The code is similar to this:

engine.UIMessagePollingEnabled = true;

 

             2. Implement a polling loop by periodically checking the Engine.IsUIMessageQueueEmpty property. You can implement it on the main thread through the while loop (which will block the main thread), or by instantiating a timer event (this does not affect the main thread, but you need to synchronize the timer with the main thread).

while(stop) 
{      
       if (!engine.IsUIMessageQueueEmpty)
            {
                UIMessage msg = engine.GetUIMessage();
                switch (msg.Event)
                {
                    case UIMessageCodes.UIMsg_StartFileExecution:
                        // do something
                        break;
                    case UIMessageCodes.xxx
                        // do something
                        break;
                    ... ...
                }
           }
}

 

              3. If the queue is not empty, call the Engine.GetUIMessage method to obtain the next user interface message from the engine. Do not check the queue again until you complete whatever action the user interface message requires and release all references to the UIMessage object.

                If you don't read the UI message and process it in time, your execution will be suspended temporarily, and you can't continue to receive the next message (don't take too long to operate during processing, which will make your test time longer)

                When you finish processing a message, you need to explicitly confirm it through the following code

msg.Acknowledge();

 

 

hope these will help you.

 

0 Kudos
Message 2 of 6
(1,052 Views)

Thanks for reply!

 

What if I do not need to process any UI messages from teststand?

I just need to start sequence and to know that it finished execution

0 Kudos
Message 3 of 6
(1,044 Views)
Solution
Accepted by topic author pawhan11

I just tried to use the Execution.WaitForEndEx method. If the timeout is set to -1, it seems that seq has not been executed. Then I checked the document:

 

Returns True when the execution ends or False when the timeout occurs.

 

So I tried to use a bool variable to receive its result, but I couldn't receive any information.

If I change the timeout to exceed the time of my seq run, for example, 30s, it directly return false each time (no waiting for 30s at all), which means that the execution timeout is over. I can't understand that.

So I suggest that you still need to use UI message according to UIMessageCodes.UIMsg_EndExecution message indicates that the execution is over.

0 Kudos
Message 4 of 6
(1,025 Views)

Thanks, made it work using pooling for ui events.

0 Kudos
Message 5 of 6
(1,021 Views)

Hi Teacher,

 I am going to launch a SequenceFile in C# ,and get the value of running step&limit&result,but no idea.Can you help me some instruction? I apprieciate if any doucument can be shared.

0 Kudos
Message 6 of 6
(541 Views)