NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Failed to call Engine.StartLoginLogoutCallback to display user login dialog in C# code

I'm upgrading our custom operator interface using C# running in NET 2.0. I use Microsoft Windows Forms controls for building GUI. TestStand version is 3.1. I grab TestStand Engine Class ActiveX Control from toolbox in to the form just as I did before in my VB project. In the project references list, AxTS and TS are added in. I can call TestStand API functions through the engine object, for example I can load sequence files, create property objects, get engine properties. But when I call engine's StartLoginLogoutCallback(false, true), the user login dialog is not displayed as expected. By tracing into UI message handler code, I do not see execution start and execution end UI message, which means the fontend callback sequence is not executed or is not executed properly. I doubt that calling engine's NewExecution in my code will also have problem though I haven't tested. Has anybody encountered same problem before? Thanks for any answer in advance.
0 Kudos
Message 1 of 9
(4,668 Views)

Hello cvyao,

 

I suggest you try Engine.CallFrontEndCallbackEx. Take a look at this method in the TestStand Help. I believe this will accomplish what you are trying to do. 

Manooch H.
National Instruments
Message 2 of 9
(4,639 Views)

Hi Manooch,

 

Thank you very much for the help. I tried Engine.CallFrontEndCallbackEx, but it still doesn't work for me. I'm using TestStand 3.1. I created a very simple C# Windows application with Visual Studio 2005. In the toolbox of the project I Selected "Choose Items..." context menu to display the "Choose Toolbox Items" dialog. In the "COM Components" tab of the dialog I selected "TestStand Engine Class" so that I got reference to the TestStand engine in my project. The project compiles OK, The method to login/logout is as following:

 

 private void StartLoginLogoutCallback(bool logoutOnly, bool isInitialLogin)

{

    PropertyObject args = _engine.NewPropertyObject (PropertyValueTypes.PropValType_Container, false, "", 0);

    args.SetValBoolean ("logoutOnly", 1/*PropOption_InsertIfMissing*/, logoutOnly);    args.SetValBoolean (

"isInitialLogin", 1, isInitialLogin);    _engine.CallFrontEndCallbackEx ("LoginLogout", args, TypeConflictHandlerTypes.ConflictHandler_Error, 0);

}

 

This method is called when the form is loaded:

 

 private void Form1_Load (object sender, EventArgs e)

{

    StartLoginLogoutCallback (
false, true);

}

 

I also tried to call StartLoginLogoutCallback method in a button click event handler, but it doesn't work either. I also notice that when I press "Exit" button which causes form's Close() method to be called, the application form does not close and I have to kill the application with task manager or to stop debugging if it is running in debug mode.

 

Could you please tell what's wrong? Thanks!

 

- cfyao

 

 

0 Kudos
Message 3 of 9
(4,628 Views)

Hi cfyao,

 

It sounds to me like you're trying to build your User Interface by making direct calls to the TestStand Engine. There are pre-built UI controls that ship with TestStand, such as the Application Manager, that take care of calling things like calling FrontEndCallbacks.seq. In addition, TestStand ships with pre-built User Interfaces. It also provides the source code for these User Interfaces. The User Interfaces built in C# (Simple and Full-Featured), along with the respective source code, can be found in the following directories:

 

Program Files\National Instruments\TestStand 3.x\OperatorInterfaces\User\Simple\CSharp

 

Program Files\National Instruments\TestStand 3.x\OperatorInterfaces\User\Full-Featured\CSharp

 

Take a look at these User Interfaces and how they are architected. This should help you with yours. 

Manooch H.
National Instruments
0 Kudos
Message 4 of 9
(4,610 Views)

Hi Manooch,

 

Yes, I'm building my own user interface which meets our special needs and is quite different then NI's. It was written in VB and we want to migrate it to .NET using C#. We have used this in the production for many years stating from TestStand v1, and we don't want to change it. I know that NI provides examples to build operator interface, but these examples use NI's custom ActiveX controls and I will not use them because I cannot build operator interface we want by using those components. So back to my original question. I used NI's Engine Class ActiveX control in my project, I can call engine's methods such as load sequence file to display a sequence in my GUI. But executing a sequence seems problematic. When I call engine's CallFrontendCallback method which will invoke FronEndCallback.seq, not only the login dialog does not appear, there is not ExecutionStart and ExecutionEnd UI message fired. When I close the application, it just hangs and I have to kill it. NI's example code calls AxApplicationMgr.Start() to do some initialization and display login dialog, but I don't know how AxApplicationMgr accomplishes this since I do not have access to the code of AxapplicationMgr.

 

I also tried to build a .NET wrapper to teapi.dll ActiveX control by using tlbimp and used it in my project, then login dialog was displayed. But after I added UI message event handler to the engine, login dialog was gone again, and there was no UI message fired. Another experiment I did is to use AxApplicationMgr in my project, but when I dragged the icon representing AxApplicationMgr to the form, an error message dialog shew the message "Faile to imporet the ActiveX control. Please ensure it is properly registered." I'm using Visual Studio 2005. On the other hand, I can load NI's example C# project into Visual Studio 2005 and build, run the project.

 

I hope I have described the problem I'm having clearly.

 

Thank you very much!

 

cfyao

 

0 Kudos
Message 5 of 9
(4,601 Views)

cfyao -

I think the only way that we may be able to help is for you to share an example UI that illustrates the problem. Can you simplify down your VS 2005 C# application so that you could share it with us. Ideally, if it could reproduce the problem by just running it, that would be helpful. You could post it to the forum or put it on NI's ftp site at ftp://ftp.ni.com/incoming/.

Scott Richardson
https://testeract.com
0 Kudos
Message 6 of 9
(4,592 Views)

Thanks Scott!

 

I have put two zip files, SimpleTsEngineTest.zip and SimpleTsEngineTest2.zip to NI's ftp site. The first zip file contains the project that calls LoginLogout fontend callback, the second one contains the project that loads a sequence file and executes the first sequence in the sequence file. A simple sequence file is also included the zip file. I'm using TestStand v3.1 engine in both projects. when I ran both example projects, the only UI message event detected was StartFileExecution, and both programs hung after press exit button.

 

cfyao

0 Kudos
Message 7 of 9
(4,587 Views)

To cfyao -

Sharing the application helped. The issue is that the engine is waiting for an acknowledge for its first message sent to the UI. The engine cannot send a second until that happens. If you do not manually acknowledge the message, you are relying on C# to release the object, which will also acknowledge the message. Since C# does garbage collection, the message will not be released until the garbage collector decides to, and it this case it never does, so the engine is still waiting.

 

For example:

        private void _engine_UIMessageEvent(object sender, _TEEngineEvents_UIMessageEventEvent e)
        {
            int i = 0;
            switch (e.msg.Event)
            {
            ...
            }
            e.msg.Acknowledge();
        }

 

Since you are doing things at such a low level, there might be other issues like this that could impact you as you go. In general NI highly recommends using TestStand 4.0 or later with C# and using the UI controls that come with them. For your application, using the ApplicationMgr control handles a lot of issues for you, even for a simple application like this.

Scott Richardson
https://testeract.com
0 Kudos
Message 8 of 9
(4,552 Views)

Hi Scott,

 

Thank you very much for the help!

 

cfyao

0 Kudos
Message 9 of 9
(4,537 Views)