From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Writing a C# Application with the TestStand Engine API

Hello,

I know it's recommended to use the TestStand User Interface Controls to write apps, but I want to write one using the TestStand Engine API.

I've been able to add an ApplicationMgr to my app and get an engine from it.

Using the TestStand Sequence Editor, I wrote a trivial sequence: a single step which is a Message Popup. I am able to Execute the sequence in the Sequence Editor, and I would now like to make my program execute it.

I thought this would execute my sequence and show me my popup:



SequenceFile sequenceFile = engine.GetSequenceFileEx ( fileName, GetSeqFileOptions.GetSeqFile_OperatorInterfaceFlags, TypeConflictHandlerTypes.ConflictHandler_Error);

object ignoredOptionalArg = System.Type.Missing;

Execution ex = engine.NewExecution(sequenceFile, sequenceFile.GetSequence(0).Name, null, false, ExecutionTypeMask.ExecTypeMask_Normal, ignoredOptionalArg, ignoredOptionalArg, ignoredOptionalArg);

int startCount = ex.StartCount;

engine.ReleaseSequenceFileEx(sequenceFile,0);



but nothing happens. What am I doing wrong?

Thanks,
Jeff
0 Kudos
Message 1 of 5
(4,109 Views)
Are you immediately exiting your application because you are expecting your sequence to run to completion before Engine.NewExecution returns? Keep in mind that NewExecution starts a new thread that posts events to the main thread. If the main thread exits immediately, these events aren't handled and the execution never starts.

Since you are using the ApplicationMgr, I strongly suggest starting with the Simple C# OI example. Delete the SequenceView control and/or any buttons you don't want and delete any code that references the deleted controls. Don't delete the SequenceFileViewMgr and ExecutionViewMgr controls (which are invisible at runtime). By starting with the simple OI, you guarantee that you have the correct infrastructure implemented to start up the engine, handle events while executing, and shut down gracefully.

To load your file, call ApplicationMgr.OpenSequenceFile. To run the file, you can call SequenceFileViewMgr.GetCommand(command, index).Execute(true).

To run the sequence file without using a process model entry point, pass CommandKind_RunCurrentSequence, CommandKind_RunSelectedSteps, or CommandKind_LoopOnSelectedSteps to command. Pass 0 to index.

To run the sequence file with a process model entry point, pass CommandKind_ExecutionEntryPoints_Set or CommandKind_LoopOnSelectedStepsUsingEntryPoints_Set to command. Pass 0 to index for the TestUUTs entry point. Pass 1 to index for the Single Pass entry point.

Alternatively, you can connect these commands to buttons or menu items as the examples demonstrate.

- James
0 Kudos
Message 2 of 5
(4,099 Views)
Thank you for your help. I did what you suggested and was able to run my toy sequence!

Next question: The buttons from the Simple C# OI app work fine, but when I add a new AxButton to my panel and try to hook it up just like an existing one, my call to axApplicationMgr.ConnectCommand(...) with it always throws an exception: "A SequenceFileViewMgr control is required".

I have a SequenceFileViewMgr control on my panel, and as far as I can see, none of the buttons left over from the Simple OI app have any connection to it but they work.

Any ideas?

Thanks,
Jeff
0 Kudos
Message 3 of 5
(4,087 Views)
That error means that the particular command you are connecting can only be connected to a SequenceFileViewMgr control. This is probably because the command needs to know what sequence file or what selected sequence steps to operate upon.

The online help for the CommandKinds enumeration lists all the commands. For commands that require a connection to specific types of manager controls, the required control types are specified in the command description.
0 Kudos
Message 4 of 5
(4,075 Views)
Aha! Thank you!
Being new to TestStand, I had overlooked the fact that,as you said, I was connecting a command to the wrong type of thing. Once I connected it to the right one, it worked fine.

Thanks again,
Jeff
0 Kudos
Message 5 of 5
(4,064 Views)