NI TestStand

Showing results for 
Search instead for 
Did you mean: 

TestStand - Catch event or implement delegate from .NET DLL

Go to solution



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);
                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?





0 Kudos
Message 1 of 5

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



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?



0 Kudos
Message 2 of 5

Thanks Luis.


This is an example of a LabView event servicing.


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
Accepted by migsantiago

Hi Santiago,


just visit this thread to get introduced.


AL.B  had provided a link to an example.

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





Sessions NI-Week 2017 2016
Feedback or kudos are welcome
Message 4 of 5

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:


Thanks, I will review it.



0 Kudos
Message 5 of 5