Showing results for 
Search instead for 
Did you mean: 

Returning data from a Reg Event Callback to the calling VI

Go to solution



I am new to LabVIEW and approach it from a C# programming background. I have a DLL library written in C# connected up and a .NET Reg Event Callback listening to an event in the DLL. This part works. I can receive an integer value from my DLL when the event fires - so far so good.


However, having this integer available only in the VI which is referenced by the Reg Event Callback is useless - I need this integer passed back to the calling VI so that I can work with it. I tried wiring a numeric indicator up to an output in the subVI but this generates a function conflict on the wire connecting the Event Callback to the strictly typed VI Ref. Please see the attached illustration.


Please help!

0 Kudos
Message 1 of 10

I'm not too familiar with event callbacks but I believe you can do this by passing a queue/user event reference into the 'User Parameter' variant input of the event callback node.


In your callback VI, you can use variant to data to convert back into your queue/event data type and generate the event/enqueue which you can listen to from your calling VI.

LabVIEW Champion, CLA, CLED, CTD
0 Kudos
Message 2 of 10

Hi @Sam_Sharp,


I have found an example online which seems to allude to your explanation, but I cannot figure out how it is working or how to use your suggestion. Can you shed any light? The example is attached.



0 Kudos
Message 3 of 10

I took the example you gave and modified it as follows to demonstrate what you want to do (whilst also learning something I said I haven't used callbacks much/at all).


In the Callback VI:


You can change the data type of 'User Parameter' to whatever you want and it will adapt on the Reg Event Callback node. Here I am firing an event with some string data. Make sure that the name and connector pane are the same (I guess it has to match the prototype).


Main/Caller VI:


This is where I create the event, feed it into the callback VI and then register for the event in the caller. When the callback VI fires, it will generate the event as above and you should see the string data appear in the caller.

LabVIEW Champion, CLA, CLED, CTD
Message 4 of 10

 Sorry for needing handheld through this - but i can't find those elements you are using (the yellow coloured blocks). Could you also send me the example you made?


Thank you

0 Kudos
Message 5 of 10
Accepted by topic author ChrisBonnar

Those "yellow blocks" are all from the Events palette, under "Dialog & User Interface". They are Create User Event, Generate User Event, Destroy User Event, and Unregister for Events.


EDIT: also see this thread for example code you can download:

0 Kudos
Message 6 of 10

Sorry for not posting the code - I don't like to post VIs unless I've had time to test/verify that it works first and I was about to go into a meeting. If you haven't used user events before then I'd suggest looking at some of the examples in LabVIEW.


You don't have to use user events - they're just a neat way of passing data around and as it's an event callback it makes sense to handle it as an event in LabVIEW.

LabVIEW Champion, CLA, CLED, CTD
0 Kudos
Message 7 of 10

I don't think It is necessary to pass a queue reference, You can use Obtain Queue vi in the callback vi and use the same queue name.


EDIT, just realized you're using User Event not queue or notifier, so passing a reference might be necessary.



0 Kudos
Message 8 of 10
Even with a queue or notifier, it's preferable to wire the queue reference rather than use a named queue. There's no chance of using the wrong name and receiving no data, and you don't have to remember to release the queue reference in the callback (with a named queue, you would have a memory leak if you didn't release the reference in the callback).
Message 9 of 10

Thanks for your help everyone, I have marked the post that helped me reach the solution.

0 Kudos
Message 10 of 10