07-10-2008 08:37 AM
Thanks Rolf,
when I read "write a wrapper DLL that provides that callback function pointer and in there you translate that event into a more LabVIEW user friendly event" it just confused me even more. I understand LabVIEW and occurances and user events; but not DLLs.
What would have made this a lot clearer (to me at least) would be to say that the input to the client's DLL (where a pointer to a user function) is expected will be wired to an user event refnum with type = adapt to type, and Data Format = Handles by Value.
The LabVIEW side of this is very straight forward to me, but keeping the client's DLL happy is where you keep losing me.
even your earlier posting:
http://forums.ni.com/ni/board/message?board.id=170&thread.id=88974&view=by_date_ascending&page=1
didn't help until I saw the uservevent.zip example that you attached (a picture really is worth a thousand words)
thanks again
07-10-2008 09:14 AM
No, that may not be right, just reading this article http://zone.ni.com/devzone/cda/tut/p/id/4852 , and maybe the event reference gets fed to the wrapper DLL(?) so then what gets fed to the input of client's DLL?
back to the drawing board
07-10-2008 12:22 PM - edited 07-10-2008 12:25 PM
No, no! The user event refnum is NOT a callback function pointer! It's the refnm that is passed to PostLVUserEvent() as first parameter. So you will write a DLL which provides the actual callback function, and a second function to be called by LabVIEW to install that callback and possibly to revoke it too, dpending on the DLL.
@lmd2 wrote:
No, that may not be right, just reading this article http://zone.ni.com/devzone/cda/tut/p/id/4852 , and maybe the event reference gets fed to the wrapper DLL(?) so then what gets fed to the input of client's DLL?
back to the drawing board
07-10-2008 12:55 PM
Let's step back a second. This entire effort is to convert a device driver written in C to LabVIEW. LabVIEW programmers aren't going to be writing callback functions in C anyway, The intent is when one of the interrupts enabled in the mask occurrs, the user can do 'something'. Ideally if one of the interrupts occurrs a LabVIEW programmer will want to run some G code (not C code).
What would be ideal is some way to coerce or cast an event reference so that the clients function would accept it, and then simply run some LabVIEW code (say in an event structure) and skip the C function pointer completely?
Basically I want to use the clients function which triggers on an interrupt to run something on my block diagram, not really a C function - otherwise how will this be usefull to C-challenged LabVIEW coders
07-10-2008 01:13 PM - edited 07-10-2008 01:22 PM
Well, it would be ideal but basically impossible. LabVIEW simply has not enough information to be able to do such coercion automatically and a configuration dialog that would allow you to tell LabVIEW how to do this right would be an entire magnitued more complicated than the Call Library Node configurationalready is (which would basically mean that only people can understand it that know enough that they would go the C wrapper route anyhow).
@lmd2 wrote:
Let's step back a second. This entire effort is to convert a device driver written in C to LabVIEW. LabVIEW programmers aren't going to be writing callback functions in C anyway, The intent is when one of the interrupts enabled in the mask occurrs, the user can do 'something'. Ideally if one of the interrupts occurrs a LabVIEW programmer will want to run some G code (not C code).
What would be ideal is some way to coerce or cast an event reference so that the clients function would accept it, and then simply run some LabVIEW code (say in an event structure) and skip the C function pointer completely?
Basically I want to use the clients function which triggers on an interrupt to run something on my block diagram, not really a C function - otherwise how will this be usefull to C-challenged LabVIEW coders
07-10-2008 02:13 PM
ok so I have to learn this
found an example "Posting Events to a LabVIEW Event Structure From a Dll" at http://zone.ni.com/devzone/cda/epd/p/id/1480
I'll look this over and try to gain some insight. One thing that still makes no sense to me, I have to wire something into the input of the CLFN for the original function, in my earlier problem (pointer to a pointer to a struct) my dll allocates a block of memory, returns the address which then gets passed to the client's dll. In this case what if anything gets passed to the clients dll?
07-10-2008 03:44 PM
07-11-2008 12:43 AM - edited 07-11-2008 12:47 AM
Well I assumed that this would be made clear by the userevent.zip file that you found in my post earlier on. This is basically more similar to what you try to do than the NI example you found in your previous post.
@lmd2 wrote:
ok, spoke to NI - if I understand this now, the CLFN will call my wrapper DLL, which will access the clients function internally, LabVIEW will not call the clients function through a CLFN ever. Glad someone finally said that it clears up a number of misconceptions.So nothing gets 'wired'. But even internally I need to supply some input to the clients function (textually). Since we want to do the real action on the block diagram would this be a call to a dummy function that simply returns a status? Can that dummy function be part of the same DLL or should it be external?
Starting to make sense, let me think on this a little more
07-14-2008 08:13 AM
Hi Rolf
conceptually I think I am finally getting this (nice when the light finally comes on)
I am working on the mechanics, bit of a learning curve but I am finding examples, I'll get it.
A question on architecture, or organization - I am going to need two functions to handle the wrapping of "the pointer to a function" (in one of the client's functions) and one or two to handle the earlier issue of "pointer to a pointer" and maybe others as I continue working on this driver project - Is it considered good practice to have a single DLL containing all of these pairs of functions?
thanx for all your help; and your patience -
lmd2
07-14-2008 08:33 AM
Definitly! It will make maintianing that project much more easy. It would be a different story when you would support two rather different drivers. While you could still put everything in one file it may be more sensible to keep a differetn DLL for each driver type, eventhough if that might mean copying some functionality, but it is all a question of good sense, your own preferences and some "Fingerspitzengefühl".
@lmd2 wrote:
Hi Rolf
conceptually I think I am finally getting this (nice when the light finally comes on)
I am working on the mechanics, bit of a learning curve but I am finding examples, I'll get it.
A question on architecture, or organization - I am going to need two functions to handle the wrapping of "the pointer to a function" (in one of the client's functions) and one or two to handle the earlier issue of "pointer to a pointer" and maybe others as I continue working on this driver project - Is it considered good practice to have a single DLL containing all of these pairs of functions?
thanx for all your help; and your patience -lmd2