LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Callback from DLL file, back to Labview 6.1 event, How?

I'm interfacing an instrument to Labview 6.1 via USB under Windows 2000 using a DLL. It is operational, but I would prefer not doing updates by polling or based upon a timer. I would prefer to use a callback function that is triggered by a "DataAvailable" Event, which I have available.

My question is, is there a way that I can pass a Labview Event function handle to the DLL callback function so that the Labview Event is triggered when the DLL function triggers a "DataAvailable" event?

I've seen some of the discussion on similar topics, but most are related to keyboard/mouse events or specifically for the LV serial driver and not an external event from a DLL.
0 Kudos
Message 1 of 11
(4,587 Views)
What you suggest is not possible. There is no way to pass a LabVIEW Event reference to external code or to trigger a LabVIEW event from inside a DLL callback function. Actually, there is currently no way to programmatically trigger a LabVIEW event structure. It only works with user events. Polling is still probably your best option. If you use a fair delay in the polling loop, it really shouldn't rob you of too much processor time.
0 Kudos
Message 2 of 11
(4,587 Views)
I've read in zone.ni about "Setting Occurrences from C in Windows" that is is possible to use PostMessage to raise a Labview occurrence from Outside of Labview. This wouldn't have acceptable time response for my application, (Windows message handler isn't fast), but would it be possible to do something similar using and external event to signal Labview to go get more data (not necessary a Labview event).

Also, the discussion in zone.ni "Passing a Variety of Datatypes from a DLL to Labview" looks interesting. I'll have to run an experiment using GetModuleHandle.
0 Kudos
Message 3 of 11
(4,587 Views)
> I've read in zone.ni about "Setting Occurrences from C in Windows"
> that is is possible to use PostMessage to raise a Labview occurrence
> from Outside of Labview. This wouldn't have acceptable time response
> for my application, (Windows message handler isn't fast), but would it
> be possible to do something similar using and external event to signal
> Labview to go get more data (not necessary a Labview event).
>
> Also, the discussion in zone.ni "Passing a Variety of Datatypes from a
> DLL to Labview" looks interesting. I'll have to run an experiment
> using GetModuleHandle.
>

I'm not sure what your timing requirements are, but the setting an
occurrence from C code approach is exactly what drivers written by NI
do. CAN, the old D
DE VIs, DAQ occurrences, and pretty much all
asynchronous nodes, even the wait MS node in LV work this way.

I haven't looked at the article in awhile, so I'm not sure how indepth
it goes. It is possible to set the occurrence by sending a windows
message, but it is also possible to set the occurrence by calling the
occur function directly. You can also arrange for the LV thread that is
waiting on the occurrence to be running at a higher priority to help
reduce latencies.

Greg McKaskle
0 Kudos
Message 4 of 11
(4,587 Views)
I'm following the zone.ni article "Setting Occurrences from C in Windows" and it appears to do what I want to do. However, the article is incomplete because it does not show the Callback setup from inside Labview. I already have a DLL working with Labview, so I know how to do that part.

My question is, what data type do I use in the Call Library Function Callback definition in Labview in order to pass an occurrence?

One of my DLL calling parameters is of type "LVRefNum" so that I can use it in the call to Occur
MgErr __cdecl Occur (LVRefNum OccurrencNum)

as per the "Setting Occurrences..." article. LVRefNum is defined as type "MagicCookie" in extcode.h but this doesn't help me. The output of GenerateOccurrence is of type Occurrenc
e and I need to map/convert that to a data type supported by the Call Function Library block.

Any suggested would be appreciated.

Right now I just get a Labview error telling me the types are incompatible. The DLL compiles fine.
0 Kudos
Message 5 of 11
(4,587 Views)
....
> Right now I just get a Labview error telling me the types are
> incompatible. The DLL compiles fine.
>

I believe that you want to make the Call Library Node's parameter be
Adapt to Type. You could also type cast the refnum to be an I32 and
pass it that way.

Greg McKaskle
0 Kudos
Message 6 of 11
(4,587 Views)
Yep. I finally figured that much out. The new issue is getting the type right in the DLL and the call to "Occur". When I select "generate code" with the right mouse button on the the Call Library node, it tells me that Adapt to Type resulting in the parameter:

(...., LVRefNum *OccurrenceRefnum );

I'm trying this out. If it works out I'll post the attached files as an example for future reference.
0 Kudos
Message 8 of 11
(4,587 Views)
Bit late, but what about generating an ActiveX event and within Labview
waiting on that event? This is probably what the event structure does under
the hood anyway.
--
Craig Graham, Software Engineer
Applied Analysis and Integration Limited, UK


"ff" wrote in message
news:5065000000050000006F680000-1012609683000@exchange.ni.com...
> Yep. I finally figured that much out. The new issue is getting the
> type right in the DLL and the call to "Occur". When I select
> "generate code" with the right mouse button on the the Call Library
> node, it tells me that Adapt to Type resulting in the parameter:
>
> (...., LVRefNum *OccurrenceRefnum );
>
> I'm trying this out. If it works out I'll post
the attached files as
> an example for future reference.
0 Kudos
Message 9 of 11
(4,587 Views)
My understanding is that Events would be processed through the Windows Message system and that Occurrences would be process more like Posix signals. In that sense I believe occurrences should have a quicker response.
0 Kudos
Message 10 of 11
(4,587 Views)
Hi,

A callback function is not different from a normal function. Windows calls
them on certain events, but you can call them yourself.

If you want it to be called by LabVIEW on an event, build a dll wrapper that
calls the callback with the needed parameters. To make this happen, you do
need the address of the callback (that you probably made yourself, so that
won't be any problem). Execute this dll if the LabVIEW event happend.

Regards,

Wiebe.


"ff" wrote in message
news:50650000000800000028400000-1012609683000@exchange.ni.com...
> I'm interfacing an instrument to Labview 6.1 via USB under Windows
> 2000 using a DLL. It is operational, but I would prefer not doing
> updates by polling or based upon a timer. I would prefer to use a
> callback function t
hat is triggered by a "DataAvailable" Event, which
> I have available.
>
> My question is, is there a way that I can pass a Labview Event
> function handle to the DLL callback function so that the Labview Event
> is triggered when the DLL function triggers a "DataAvailable" event?
>
> I've seen some of the discussion on similar topics, but most are
> related to keyboard/mouse events or specifically for the LV serial
> driver and not an external event from a DLL.
0 Kudos
Message 7 of 11
(4,587 Views)