LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LabView user-event from external dll source

Hi!

I'm dealing with the following issue:
I use a CAN sniffer device, wich sends data over USB to a PC. The main goal is to create a vi that can process the incoming data. I already have a vi wich works with polling mechanism. It calls external DLL functions with the "Call library function node". The main problem is the polling mechanism.
I would like to recreate this vi so that it would work event-driven. I have an other application, written in C++, that does the same thing, and it gets interrupts from a DLL, when a new data is available in the input buffer.
The callback mechanism is implemented in the DLL.
In LabView I would like to do tha same thing. There is the "event case structure", but there is no option for defining such user-events, that i would prefer.
I have found a similar topic, there the solution is "occurrences". The occurrence is called from a DLL, too. But this solution uses the "waiting for occurrence to set", that is an endless-loop-like thing.
The other thing I've found is the ActiveX and .NET events. I don't know, probably that is the solution.

Anyway: is there a possibility to create such events, that can be generated from a simple external DLL and can be handled by "event case structure"? How should I do this?
Or how NI does this? I mean that NIs DAQ cards must use some similar methods for data processing. Is there some tutorial or support about it?

Thank you for your answer!

0 Kudos
Message 1 of 57
(17,351 Views)
You can create a DLL build in LabVIEW that call a user event when a particular function is called. You would have to init the LabVIEW dll with the user event reference and use the WIN API functions to retrieve the function pointer of the callback function in the LabVIEW dll. This pointer can be used to init the C++ dll and the C++ dll is now able to use the callback function of the LabVIEW dll to generate user events.

I have used this technique in a recent project of mine. I will take some time to implement.
Regards,
André (CLA, CLED)
Message 2 of 57
(17,333 Views)
A picture to support my explaination:




Message Edited by andre.buurman@carya on 06-18-2008 11:29 AM
Regards,
André (CLA, CLED)
0 Kudos
Message 3 of 57
(17,327 Views)
Thanks for the rapid answer!

I will try this. But may I ask, why the Labview.dll is needed? Or what difference is there between that and the simple dll?
And this user event can be than added to the event-case-structure, or it can be handled in another way?
Sorry for my stupid questions, but Im beginner in this topic.

Thanks:
Cs.Nemes
0 Kudos
Message 4 of 57
(17,316 Views)


@waszil wrote:
Thanks for the rapid answer!

I will try this. But may I ask, why the Labview.dll is needed? Or what difference is there between that and the simple dll?
And this user event can be than added to the event-case-structure, or it can be handled in another way?
Sorry for my stupid questions, but Im beginner in this topic.

Thanks:
Cs.Nemes


The LabVIEW DLL is needed to get a C function pointer for a LabVIEW VI. Basically the DLL Builder generates a C wrapper function that loads the VI, passes its input parameters to the input controls on the front panel, invokes the VI and then returns the values from the output controls to the output parameters of the function.

If you know C you can write a C wrapper DLL instead that passes the external event as occurrence or user event to LabVIEW and import that DLL with the Call Library Node. But that requires you to write C code.

Still some good understanding of C function pointers and C datatypes would definitly help  for the LabVIEW DLL case too, to make it work and work reliably.

Rolf Kalbermatter
Rolf Kalbermatter
My Blog
0 Kudos
Message 5 of 57
(17,310 Views)
If the dll is used from within LabVIEW, you can call PostUserEvent . It
takes a reference to the registered event (as I32) and the data. The data
has to be in the right form, or crashes are likelly to happen...

Regards,

Wiebe.


0 Kudos
Message 6 of 57
(17,304 Views)

Hi!

"...is there a possibility to create such events, that can be generated from a simple external DLL and can be handled by "event case structure"?..."

I'll suggest to use PostLVUserEvent function. Its pretty easy:
In your DLL you should call it by the following way:
 
and then use it in LabVIEW like this:
 
 
you can put PostLVUserEvent into your callback function called in DLL and get callback messages in LabVIEW.
 
See also (exactly the same example): Posting Events to a LabVIEW Event Structure From a Dll
 
best regards,
Andrey.
Message 7 of 57
(17,301 Views)

"Wiebe@CARYA" <wiNOebe.walsSPtra@carAMya.nl> wrote in message
news:4858e51e@PYROS.natinst.com...
> If the dll is used from within LabVIEW, you can call PostUserEvent . It
> takes a reference to the registered event (as I32) and the data. The data
> has to be in the right form, or crashes are likelly to happen...
>
> Regards,
>
> Wiebe.
>

Yes, PostLVUserEvent... Like Andrey said.


0 Kudos
Message 8 of 57
(17,274 Views)
It is fantastic! I did not expect such great help!
Anyway, I do have some more questions, but I think im getting to understand this whole thing.

So, how do i create this labview.dll? Where can I find the utility.h and extcode.h? I guess they implement the connectivity between labview and external codes.
And do I need some extra stuffs for building this dll?

thanks
Cs.Nemes


0 Kudos
Message 9 of 57
(17,233 Views)


@waszil wrote:
It is fantastic! I did not expect such great help!
Anyway, I do have some more questions, but I think im getting to understand this whole thing.

So, how do i create this labview.dll? Where can I find the utility.h and extcode.h? I guess they implement the connectivity between labview and external codes.
And do I need some extra stuffs for building this dll?

thanks
Cs.Nemes


You'll write in C a DLL (Visual Studio is recommended here strongly) and you find the extcode.h and other necessary files in your cintools directory inside your LabVIEW directory (if you have LabVIEW Full development System or better, it's not part of the Base package).

Also in there is a labview.lib file which you need to link with your DLL project and that will take care of importing the LabVIEW manager functions you are ging to use.

Rolf Kalbermatter



Message Edited by rolfk on 06-19-2008 10:18 AM
Rolf Kalbermatter
My Blog
Message 10 of 57
(17,229 Views)