Runjhun Posted December 9, 2013 Report Posted December 9, 2013 Hi, I want to implement the SSL Begin Read method in LabVIEW with the System DLL using the .net construtor nodes.I am successful in doing so for the synchronous Read method. But when I am trying to modify my code with the Asynchronous methods, it asks me to wire reference for a Asynchronous Callback node. I haven't worked with Event Callbacks in .net before , so I dont have much clue about the dataflow and other things.Can anyone please help me regarding creating callbacks in this particular case.Regards,Runjhun. Quote
LogMAN Posted December 9, 2013 Report Posted December 9, 2013 (edited) I can't give a solution for your specific problem, but .net callbacks are easy to understand: - Place the Register Event Callback node from the .NET palette into your VI - Wire the .NET class reference to the Event input (the third connector from top-left! not the first!) -> Now you can select an event from the drop-down box where all available Events are listed - Once you've selected your event, rightclick the VI Ref terminal and select Create Callback VI - Do whatever you want in the callback VI (like trigger a LabVIEW event) Now whenever the event is fired, your callback VI is called... Try it with a message window Hint: Wire some data to the User Parameter input of the Register Event Callback node and re-create the callback VI. This is how you could send a LabVIEW event refnum (or any type of data) into a callback VI. Hope that helps. Upload your VI if you need help for your specific solution. EDIT: Ehem, I hate to post links but: http://zone.ni.com/reference/en-XX/help/371361J-01/lvcomm/reg_event_callback/ https://decibel.ni.com/content/docs/DOC-9161 Edited December 9, 2013 by LogMAN 1 Quote
Runjhun Posted December 10, 2013 Author Report Posted December 10, 2013 Hi, I have gone through the basic working of Event Callbacks but I have found examples that are related to UI events. In my case, I am reading some data from TCP socket and I want to generate event from that using the callback, so that it becomes an Asynchronous operation. The code that I am trying to convert to LabVIEW is the SSL Stream Begin Read method. "http://msdn.microsoft.com/en-us/library/system.net.security.sslstream.beginread(v=vs.100).aspx" I have posted my VI as well but as of now its broken because there's nothing wired to the callback function. Async Read.vi Quote
LogMAN Posted December 10, 2013 Report Posted December 10, 2013 Interesting task, some VIs are missing though (from your user.lib), but I get the critical part now. As far as I know there is no way to pass a delegate from LabVIEW to a function (as there are no raw delegates in LabVIEW). Also, even though the parameter is called 'asyncCallback', it is not an event callback, but just a parameter you could pass (any?) delegate to. The delegate could be registered as an event by the caller. I searched the internet and found a similar topic: http://forums.ni.com/t5/LabVIEW/How-do-I-configure-NET-SOAPSender-AsyncCallback-in-LabVIEW/td-p/284364 The first answer states: LabVIEW 8 introduced support for .NET events but we don't have support for raw delegates (the AsyncCallback parameter)... I think this is still true. The only option I see for this is to write your own wrapper that internally handles the delegate and provides an event for LabVIEW to register to. Of course you would also have to wrap the method you want to call in order to provide a method without the delegate parameter. I'm quite sure I've seen a similar topic here before... I guess... 1 Quote
Runjhun Posted December 10, 2013 Author Report Posted December 10, 2013 Yes. So I am trying to build my own callback but the problem is the callback function has an argument of type 'IAsyncResult'. But when I am selecting the consturtor node for this class, I get the message as 'There are no public constructors for this class'. What to do in this case ? Quote
ned Posted December 10, 2013 Report Posted December 10, 2013 IAsyncResult is an interface, not a concrete class, so there is no constructor for it. You need a class that implements that interface. 1 Quote
Runjhun Posted January 13, 2014 Author Report Posted January 13, 2014 ned, can you please elaborate on this. May be with an example. I understand Asynchronous calls are difficult implementation in .net as well as LabVIEW but in my project I am not seeing any way out here for that. I have to implement few methods as asynchronous only. Can you please help here ? Runjhun Quote
ned Posted January 19, 2014 Report Posted January 19, 2014 In what language are you trying to write your callback? You cannot do it in LabVIEW. In C# you need to create a class that implements the correct interface, and call the constructor for that class. Quote
Runjhun Posted February 13, 2014 Author Report Posted February 13, 2014 I found the solution to my problem. I had to write a .net application that was triggering an event whenever bytes were received on a socket. And as LogMan specified earlier, I used Regiter for .net Event node and passed the socket reference to it. With that whatever events were related to that class, they were populating in that list. So, I created a Callback VI, that would generate a Value Signaling event to an inetger array that would give me the bytes read from the socket. Appreciate everyone for their suggestions. Regards, Runjhun. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.