Jump to content

.net Event Callbacks

Go to solution Solved by Runjhun,

Recommended Posts

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.

Link to post

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.



Ehem, I hate to post links but:





Edited by LogMAN
  • Like 1
Link to post



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.



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

Link to post

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:



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...

  • Like 1
Link to post

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 ?

Link to post
  • 1 month later...

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 :)

Link to post

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.

Link to post
  • 4 weeks later...
  • Solution

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.




Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Similar Content

    • By bartek618
      I know how to run .Net executable by MainWindow() constructor but I have some resources defined in App.xaml and MainWindow() doesn't run without them. How to run application starting with App() constructor? Also I need to pass some parameters into MainWindow().
    • By William Hofmeister
      I need to access Aerotech A3200 data with LabView. The Digital Scope in the A3200 software has the capability to record data at 1kHz for 8 seconds in dedicated batches. We use LabView for all functions surrounding the motion control and have the Aerotech LabView package. Using the LabView vis we can only access data a single data point per call and I don't see how to set up a FIFO to Windows LabView. Someone must have looked at this problem lately. Can anyone steer me in the right direction?  Thanks!!
    • By LogMAN
      So this just happened to me and I'm quite confused by it. As it turns out, the .NET Constructor Node not only provides terminals for error in, error out and the reference, but actually two more "hidden" terminals:

      Notice: I left the error terminals untouched and none of the wires are connected (try it yourself). This never occurred to me. Only now, while hunting a null reference exception I found the constructor node looked "off", like this:

      The strange part is that the terminal doesn't actually carry the reference (which is why I receive the null exception). It only specifies the type. The upper left terminal is a void type input, so the wire is always broken.
      Does anyone know why these extra terminals exist? They don't seem to be part of the specification as far as I can tell.
      Any fancy things we can do with this?
    • By ATE-ENGE
      Edit: I'm asking primarily if there is a reason why/when I should/shouldn't use .net functions in my LabVIEW development. The example below is just to demonstrate a case of my question.
      I recently found a custom library that calculates SHA256 hash algorithms However, in this post I see that the same thing can be done with .net 
      My main question is: Is there any reason to build or use a custom library for something where .net functionality already exists? Are there any disadvantages to offloading work to .net ? 
    • By Gribo
      Hello, I am trying to copy multiple cells in LibreOffice, using the UNO API. I encountered an issue in the XCellRangeData object.
      The object's method returns an array of array of any() type. it seems LV can't compile this, even though the wire appears not to be broken. If I try to parse the array of array into a single dimension and then rebuild, the code is broken. See the attached files. Is there a solution for this issue? The alternative would be to copy cells one by one, which is a much slower solution.

  • Create New...

Important Information

By using this site, you agree to our Terms of Use.