07-03-2016 12:09 PM - edited 07-03-2016 12:14 PM
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
Solved! Go to Solution.
07-05-2016 04:55 PM
Hi Santiago,
I've found the following Knowledge Base article that might be helpful:
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.
07-06-2016 07:23 AM
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 ).
I'm gonna take a look at your link and I'll reply later. Thanks again.
07-06-2016 07:28 AM
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
07-12-2016 05:20 PM
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