NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

How to determine Thread, Execution for PostUIMessage

Solved!
Go to solution

Greetings:

 

I am trying to develop a TestStand application with two User Interfaces (in addition to the Sequence Editor), and I need to be able to post UI messages back and forth between the two UIs.

 

So far, I have successfully created one UI, and I can post UI messages from a TestStand sequence to my UI. great.  I passed the Application Manager reference in the constructor to the UI object.

 

Now, I want a button on my first UI to cause a UI message to be sent to my second UI ... The PostUIMessage options I have are Engine.PostUIMessage or Thread.PostUIMessage ...   in both cases I need the thread, which I don't believe I have unless I pass it explicitly in the constructor.  Ideally, I would like to pass only one object in the constructor (to keep things simple).

 

I have tried creating versions of my first UI that pass the Engine reference, or the SequenceContext reference, but I seem to be unable to  extract the info I need from these.  For instance, from the SeqContext, in theory I can get the Engine and the Thread, but when I try to get the AppMgr reference from the engine

 

                TsEngine = seqContext.Engine;
                AppMgr = (ApplicationMgrClass) TsEngine.GetInternalOption(InternalOptions.InternalOption_ApplicationManager);
 

I get the following exception:

 

The instance of the .NET class could not be retrieved.

Unable to cast COM object of type 'System.__ComObject' to class type 'NationalInstruments.TestStand.Interop.UI.ApplicationMgrClass'. COM components that enter the CLR and do not support IProvideClassInfo or that do not have any interop assembly registered will be wrapped in the __ComObject type. Instances of this type cannot be cast to any other class; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface.
Source:  SidecarLib   at 

 

Do I really have to pass the app manager reference and sequence context and the thread as separate arguments to my constructor, or have I missed something that is causing the exception above?

 

Many Thanks,

Tom MacLean

0 Kudos
Message 1 of 3
(3,431 Views)
Solution
Accepted by topic author LabCat

It seems I have found the problem.

 

The example code that I based on my UI is from the article "Launching a Floating .NET Form in TestStand".  In this example, the Application Manager reference is in a class member defined as:

 

        ApplicationMgrClass AppMgr;


If you try getting the Application manager reference from the engine like this:

 

AppMgr = (ApplicationMgrClass) seqContext.Engine.GetInternalOption(InternalOptions.InternalOption_ApplicationManager);

 

thats when the exception mentioned above is generated.   If however the Application manager reference is defined as:

 

ApplicationMgr AppMgr;

 

and it is extracted from the sequence context like this:

 

AppMgr = (ApplicationMgr) seqContext.Engine.GetInternalOption(InternalOptions.InternalOption_ApplicationManager);

 

everything works as I had intended (with no exception).

 

I hope this can save someone else some grief.

 

Cheers,

Tom MacLean

 

 

Message 2 of 3
(3,428 Views)

Thanks a lot for your explaination,

 

Works well now.

0 Kudos
Message 3 of 3
(2,791 Views)