LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

creating an interface with wrapper dll including a callback function

Hey all, LabVIEW newbie here.  I'm an expert-level C programmer but totally new to LabVIEW.  I've been reading about LabVIEW and I think I have a viable approach to my problem, but I need some input.  My company sells programmable video interface boards used primarily in Aerospace applications.  I develop and support a C/C++ API for these boards for our customers in the form of a DLL. Now, I have tasked with developing a LabVIEW interface. Here are the requirements:

- Maintain the existing C/C++ API DLL with minimal modifications to support LabVIEW

- Provide a redistributable, easy to use interface for LabVIEW that can be used by our customers.

- Maintain the interrupt callback functionality, though the application could be notified by event or other method.

 

So far, here's my plan. I'll create a wrapper DLL to handle translation of data between LabVIEW and our API DLL.  This wrapper will also handle the configuration of a callback function into the API DLL.  The callback function in the wrapper dll will probably generate a LabVIEW Event which the users LabVIEW application can upon.  Am I on the right track here?  I've been able to import our API DLL into LabVIEW and I have confirmed that I can call functions in the DLL and communicate with the board. 

 

 

0 Kudos
Message 1 of 15
(7,683 Views)

Yes you are on the right track, here are some resources that should be helpful.

 

You can call into your DLL using the Call Library Function Node or the Code Interface Node. Then distribute a LabVIEW exe (requires LVRTE) along with your DLL's You can set up a VI that used a LabVIEW event structure to call into your Call Back Functions based on triggered events, and for communication from your API to LabVIEW you can register custom user events so you can trigger a LabVIEW event from your existing API.

 

-Hunter

Message Edited by Hueter on 01-19-2010 10:37 AM
0 Kudos
Message 2 of 15
(7,661 Views)

Also I would recommend looking at This Link to guide you. Your project really is an instrument driver and those of us who will be looking for a LabVIEW way to work with your product will greatly appreciate a robust, well documented, tested set of vi's to work with. 

 

'<flame on>' Rant ahead------

Stay professional in your development.  Agilient owes an appology to the world for the HP3458A driver that they published with a DEFAULT value of "Hmmm.....Beer" for the String to display on the front of the instrument .

 

'<Flame off>'


"Should be" isn't "Is" -Jay
Message 3 of 15
(7,653 Views)

Thanks for the reply.  I'm doing the wrapper dll now.  I'll need to read up on LabVIEW events and event structures.

The way it works now with our API dll, when the app opens the device, the app hooks in a callback function to be executed when an interrupt occurs.  When there is an interrupt, this callback function is called to perform whatever the applcation needs to do.  In the LabVIEW interface, I plan to put a simple callback function in the wrapper dll and hook it into the API dll when the device is opened. When the interrupt occurs, the wrapper callback function will be called and will set the event.  Will this work?

 

Current API implementation:

Interrupt->API->ApplicationCallbackFunction

 

LabVIEW implementation:

Interrupt->API->WrapperCallbackFunction->LabVIEWEvent

 

Then I show my customers who are developing their own apps how to act upon this event. 

 

 

0 Kudos
Message 4 of 15
(7,650 Views)

I had to figure this out for the .NET side of things.  It may help, not sure.

 

I started by creating an instance of the client object seen below.  In that client object there is an event that tells users when new data is available to be displayed.  To subscribe to that event I register for the Event callback from that object.  There is a lot more on this in the NI example finder if you search for NET Event Callback for Calendar Control.  This is where I learned how to do most of this.  I had to create a separate VI for the VI Ref and wired up a Reference to the data cluster as the user parameter.  Next I create a dynamic event for that data cluster.  If the value changes I want the event structure to do something for me.  I use the NewVal and OldVal for comparison.  At this point my front panel display is updated with any new information.

 

I am not sure if this will help but I know what it was like trying to figure out how to use an event from a DLL to trigger my LabVIEW VI.  Let me know if this helped or if you need me to clarify anything. 

 

dotNET_Event_Example.png

0 Kudos
Message 5 of 15
(7,638 Views)

Matt - Yes I think this is going in the right direction, but my experience with LabVIEW limits my progress at this point.  I think what I want to use is a LabVIEW User Event.  The device is a video transceiver, and generates an interrupt upon completion of a video frame, either sending or receiving.  The device has 2 frame buffers, and the interrupt parameter value indicates which buffer.  In the User Event data I would want to put this the value of this parameter, or a third value for a "debug" interrupt that out API can also generate.

 

0 Kudos
Message 6 of 15
(7,632 Views)

What I will probably implement is similar to the MIDI Throughput example:

https://forums.ni.com/t5/Example-Code/Communicating-with-a-Windows-MIDI-Device-in-LabVIEW/ta-p/39963...

 

I need to know if I can build the wrapper dll with MSVC++ 6 or do I have to use LabWindows/CVI.  Does anyone know?

 

 

0 Kudos
Message 7 of 15
(7,611 Views)

Lookie here, I'm answering my own question. Robot surprised

 

I was able to create a "wrapper" dll containing a couple of functions, and I was able to import it into LabVIEW.   

 

Now, I need to add a parameter to one of the functions.  In the API dll, this parameter is an array of structures, so I think I will need to translate it on the wrapper dll function.  But how do I add it to the imported function (and the SubVI) in LabVIEW?   

0 Kudos
Message 8 of 15
(7,588 Views)

Which function are using currently using to "import the function". You should be able to confiure the LabVIEW interface to your DLL in the Call Library Function Node. If you need to add additional functions or paramaters just use the properties menu to add the new items.

 

CLFN properties.png

0 Kudos
Message 9 of 15
(7,574 Views)

I imported the wrapper dll and created VIs for each of the functions.  Now I need to add a parameter to the wrapper dll function.  The parameter I need to add will be a cluster array (I think) because in the warpper dll I need to convert this to/from an array of structures for the API dll.  I can figure out how to modify the wrapper dll, but I don't know how to add the parameter in Call Library Function because it's a cluster array. I also need to create the cluster array and I'm lost on that one.

 

I'm afraid that my 20+ years of C/C++ programming experience doesn't help much with LabVIEW.

0 Kudos
Message 10 of 15
(7,566 Views)