From Saturday, Nov 23rd 7:00 PM CST - Sunday, Nov 24th 7:45 AM CST, 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: 

TestStand - Catch event or implement delegate from .NET DLL

Solved!
Go to solution

Hello

 

I'm working with TestStand 2014 (32 bit) and Visual C# 2008 EE.

 

I wrote a DLL in C# to control a USB device. I have managed to instantiate an object of the main class from the DLL in TestStand. I can call methods in the DLL and they execute properly.

 

The DLL has a way to publish events from the USB device by receiving a delegate (an overloaded constructor) and then calling it asynchronously when an event occurs. A .NET Windows Form can actually pass a delegate to the DLL and the DLL calls the delegated method when the event occurs. The Windows Form just verifies that the event is processed correctly by analyzing the InvokeRequired property:

 

        /// <summary>
        /// Catch messages from the API
        /// </summary>
        /// <param name="message"></param>
        public void catchDLLStatus(string message)
        {
            if (this.InvokeRequired)
            {
                this.Invoke(new model_b_api.Model_B_Status_Delegate(catchDLLStatus), message);
            }
            else
            {
                writeConsole(lstConsole, message);
            }
        }

The delegate type that the DLL calls is very simple:

 

        //Delegate that publishes status messages to the caller
        public delegate void Model_B_Status_Delegate(string message);

All of this works as a charm in a C# Form that calls the DLL for the USB device.

 

However, in TestStand, I can only perform calls to the DLL, but I have no idea on how to implement the same delegates that the DLL would require to publish asynchronous events. I could modify the DLL to publish custom events (EventHandler perhaps), but I also do not know how I would service them in TestStand.

 

I am new at TestStand, so, please forgive if this question is out of place. I've looked everywhere, but I only have found LabView examples.

 

Can TestStand pass delegate methods to a DLL or handle events from a DLL?

 

Thanks!

 

Santiago

0 Kudos
Message 1 of 5
(4,572 Views)

Hi Santiago,

 

I've found the following Knowledge Base article that might be helpful:

 

DLL Works When Called outside of TestStand but Not When Called from TestStand

http://digital.ni.com/public.nsf/allkb/AD46B130BA24BB5C86256B8100689612

 

 

On the other side you said that you found LabVIEW examples that perform the same thing you want in teststand, right? Can you share those LabVIEW examples?

 

LuisG.

0 Kudos
Message 2 of 5
(4,531 Views)

Thanks Luis.

 

This is an example of a LabView event servicing.

 

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

 

They use a "Register Event Callback" object. I haven't found a similar feature in TestStand (I'm still new Smiley Tongue ).

 

I'm gonna take a look at your link and I'll reply later. Thanks again.

0 Kudos
Message 3 of 5
(4,519 Views)
Solution
Accepted by topic author migsantiago

Hi Santiago,

 

just visit this thread to get introduced.

http://forums.ni.com/t5/NI-TestStand/CAPL-with-TestStand/td-p/1869959/highlight/true

 

AL.B  had provided a link to an example.

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

.. and I realized that I have already consumed it.

 

Regards

 

Juergen

--Signature--
Sessions NI-Week 2017 2016
Feedback or kudos are welcome
Message 4 of 5
(4,517 Views)

LuisG., the link you posted talks about a LabWindows/CVI DLL. In my case, I'm creating a DLL from a .NET assembly. That one will not work.

 

Juergen, I read the thread... the link that contains the .NET event step types is this one:

 

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

 

Thanks, I will review it.

 

Santiago

0 Kudos
Message 5 of 5
(4,456 Views)