NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Problems Launching Sequences via Engine & No ActiveX Controls

Hello all, I am having a particular problem building a custom UI solution that does not leverage the ActiveX controls (like appmanager).  To do this I am using the engine directly.

 

I can get this code to work properly when I run it from the main of simple C# console application:

 

string strModelFileName = @"proper path to model file here";
string path = @"proper path to sequence file here";
NationalInstruments.TestStand.Interop.API.Engine myEngine = new Engine();
NationalInstruments.TestStand.Interop.API.SequenceFile mySequenceFile = myEngine.GetSequenceFile( path, 0 );
NationalInstruments.TestStand.Interop.API.SequenceFile myProcessModel = myEngine.GetSequenceFileEx( strModelFileName );
NationalInstruments.TestStand.Interop.API.Execution myExecution = myEngine.NewExecution( mySequenceFile, "Test UUTs", myProcessModel, false, 0, null, null, null );
myExecution.WaitForEndEx( -1 );
myEngine.ReleaseSequenceFileEx( mySequenceFile );
myEngine.ReleaseSequenceFileEx( myProcessModel );
myEngine.ShutDown( true );

 

However, if I call the same code from within a DLL that I am building into a larger framework, the system hangs up on the following line:

 

myExecution.WaitForEndEx( -1 );

 

The application provides a UI that is a seperate component of the framework.  Conceptually, there is a small executable that spins up and uses MEF to load a bunch of other DLLs that plug in various pieces of functionality.  One piece is the TestStand engine.

 

The DLL that wraps up the engine is just supposed to wait until it is told to launch a sequence and I get no errors but the system cant seem to get any response from the sequence execution.

 

I have a loop polling the engine for UI messages (which my sequence does post) and I don't see anything come back.  No dialogs displayed within the sequence will show.

 

Seems to me like maybe there is some issue with displaying the dialogs in this architecture?  Otherwise I cannot figure out why this code works fine in a console app but becomes unresponsive within my DLL component.

 

it is worth noting that the above code is a direct snippet from a forum post I found where someone with a similar problem seemed to get around it.  My actual code is more something like this:

 

void SetEntrypoint( string entrypoint) {         
    _loadedSeq = _engine.GetSequenceFileEx( entrypoint );
    _processModel = _engine.GetSequenceFileEx( "BatchModel.seq", GetSeqFileOptions.GetSeqFile_FindFile, TypeConflictHandlerTypes.ConflictHandler_Error );
}

void StartTest() {
    _testExecution = _engine.NewExecution( _loadedSeq, "Test UUTs", _processModel, false, 0x0, Type.Missing, Type.Missing, Type.Missing );
}

// Running in its own thread
void EnginePoller() {

    while( _running ) {
        if( !_engine.IsUIMessageQueueEmpty ) {
            HandleEngineEvent( _engine.GetUIMessage() );
        } else {
            System.Threading.Thread.Sleep( 200 );
        }
    }

}

void CreateEngine() {
    _engine = new Engine();
    _engine.LoadTypePaletteFilesEx();
    _engine.UIMessagePollingEnabled = true;
    _pollingThread = new System.Threading.Thread( EnginePoller );           _pollingThread.Start();
     _engine.CurrentUser = _engine.GetUser( "administrator" );
}

 

Any help is appreciated.

0 Kudos
Message 1 of 5
(3,650 Views)

Hello! Do you have a link to the location of the post where you obtained your snippet? Maybe there's some hints I can glean from that post. 

0 Kudos
Message 2 of 5
(3,617 Views)

https://decibel.ni.com/content/docs/DOC-29585

 

It is in the comment thread below the post.

0 Kudos
Message 3 of 5
(3,608 Views)

I see. So just to make sure I understand correctly, you're not using that first code snippet in your DLL, but using that second portion of code? Where in your code is it hanging? 

 

Also, could you go into a little more detail of what your larger application is doing? If you're using a bunch of other DLLs, is it possible you may have misconfigured something in another DLL that's causing this specific portion to hang? 

 

I apologize if I'm asking a lot of questions, but it's very odd to me that something will work as a stand alone C# app but not as a DLL

0 Kudos
Message 4 of 5
(3,600 Views)

So my original attempt (and how I want to do it) is represented in the second portion of code.

 

After failing, I found the aforementioned thread.  I put that first portion of code (from the thread) into a standalone c# console app and it worked.

 

I then copy and pasted the code that worked in the console app and put it into a function within my DLL.  This is the DLL that gets built into the larger framework.  Within the DLL it exibits different behavior.  It hangs at:

 

myExecution.WaitForEndEx( -1 );

No displays (like prebatch prompt or any in-sequence dialogs) are ever shown.

 

I did some rework last night and converted the strategy to use the Application Manager Control.  I got it working.  However, it's worth noting that if I don't manually set a sequence file combobox to the appropriate index, even if the sequence file has been opened by the app manager, I get the same behavior.  No displays shown and it executed but seems to never return.

 

I have concluded that ultimately this approach is flawed because even if I get this working there is no good way to visualize my execution without using the ActiveX controls.  I can't put visible ActiveX controls in a windows form hosted by one thread and a manager in another thread hosted by an invisible form.  This is because linking a manager component to a visible display control in different forms does not seem to work.  COM exceptions get thrown by the control.  I assume this is because windows forms are single threaded and don't like cross-thread communication.

 

I think this is a fairly significant failure of the TestStand UI features.  There should really be a platform agnostic way to listen to engine activity so that decoupled UIs can be built ontop of a local or remote TestStand engine.  I really dont want to have to build custom activex controls or post a ton of UI messages to broadcast execution state.

 

Still open to any suggestions or feedback if I am off the mark.

0 Kudos
Message 5 of 5
(3,592 Views)