01-15-2015 04:07 AM
Hi,
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!
Solved! Go to Solution.
01-15-2015 04:11 AM - edited 01-15-2015 04:11 AM
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.
01-15-2015 05:31 AM
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.
Thanks
01-15-2015 06:59 AM - edited 01-15-2015 07:00 AM
I took the example you gave and modified it as follows to demonstrate what you want to do (whilst also learning something new...like 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.
01-15-2015 07:43 AM
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
01-15-2015 10:55 AM - edited 01-15-2015 10:58 AM
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: http://forums.ni.com/t5/LabVIEW/How-to-interaction-with-Main-VI-from-Net-event-callback/m-p/2954265#...
01-16-2015 03:19 AM
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.
01-16-2015 08:08 AM - edited 01-16-2015 08:13 AM
01-16-2015 09:51 AM
01-16-2015 10:02 AM
Thanks for your help everyone, I have marked the post that helped me reach the solution.