LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Howto pass a callback function to call library function node

Hello Wiebe and Rolf,

We are looking at using external code to trigger LV occurences using dlls, as in this post.

We've had luck using

MgErr Occur(LVRefnum refnum);

but cannot pass data back to LV using

MgErr PostLVUserEvent(LVRefnum userEventRefnum, UPtr data);

 

Wiebe, we looked at the Carya.dl website to see if any posting was there from last August, but we couldn't find one. Please advise what the final solution was to pass the data.

Many Thanks,

Becca MacMaster

Nuvera Fuel Cells

0 Kudos
Message 11 of 16
(2,948 Views)
I would, personally, use the occurance approach.
 
In the DLL have a callback to get notified of when the progressbar needs to be adjusted.  In this callback use an occurance to tell LabVIEW the new values ready to be read.  Also have a helper (reader) function that LabVIEW can call to get the most current value...
 
Basically every time the LabVIEW occurance is triggered call the DLL for the new value.  To me this seems the easiest way.
 
Oooo, new forum message interface!  I like it!  Robot tongue <--- First robot tongue!
0 Kudos
Message 12 of 16
(2,948 Views)

Hi Chaos,

Thanks for your post, I think we are using occurences properly, it is in getting the data back we have the problem. The second occurence I connect does not fire, and I'm not sure how I'm supposed to get the data back? I think we may be using

MgErr PostLVUserEvent(LVRefnum userEventRefnum, UPtr data);

incorrectly.

Is there any example code that you know of that we could look into?

Many Thanks,

0 Kudos
Message 13 of 16
(2,944 Views)
Well all I was saying there is no need to get the data back on the occurance itself.  The occurance can trigger a Call Library Function Node to get the data from an exported function in the DLL if you code it that way.  I have used it before in the past but I dont have a good example at the moment.
0 Kudos
Message 14 of 16
(2,940 Views)
Well lets have a look at this function.

MgErr PostLVUserEvent(LVRefnum userEventRefnum, UPtr data);

The first parameter is a LabVIEW refnum. This is basically just the refnum as created by the Create User Event function.

The second is a pointer to the unflattened LabVIEW data the user event will take. So in the case of a user event containing an int32 you would pass here an int32 * to it. Just try it out with this or slightly different configurations.

Rolf Kalbermatter
Rolf Kalbermatter
My Blog
0 Kudos
Message 15 of 16
(2,935 Views)
Ok, I was almost sure that there would be an example for this in the Developer Exchange already but I couldn't find it. So I dug up some code I had developed years ago to use Occurrences and changed it to use User Events instead. Here is the example. While it does use Windows Multimedia functions (because that was the simplest function to find with callback function) the LVPostUserEvent function is in fact a plattform independant function and therefore could be used form a callback in a shared library on any LabVIEW 7 platform.
   
The attached VI is LabVIEW 7.1 altough PostLVUserEvent should be available since LabVIEW 7.0. No guarantee though that it will work exactly the same on LabVIEW 7.0 platforms or even be implemented on every platform under LabVIEW 7.0.

Rolf Kalbermatter

Message Edited by rolfk on 07-03-2005 08:15 AM

Message Edited by rolfk on 07-03-2005 08:16 AM

Rolf Kalbermatter
My Blog
0 Kudos
Message 16 of 16
(2,935 Views)