LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

What are my options for linking static C++ libraries to LabView

I am using a Cypress CY7C68013A USB chip to develop some hardware that will connect to a PC. I want to use LabView to send and receive data via this interface. The driver provided by Cypress for this IC is accessed via a statically compiled MS Visual C++ library called CyAPI.lib. I do not have access to the source code. I do have documentation on the API. I suspect that I will have to write a C wrapper for each object field/method.  I would like to avoid this if possible.  What are my options for getting LabView to access the CyAPI.lib?

 

Any help would be greatly appreciated!

0 Kudos
Message 1 of 6
(7,215 Views)

Hi,

To quote Microsoft : "A static library is a file containing objects and their functions and data that is linked into your program when the executable file is built. This topic explains how to create the starter files and project settings for a static library. You can link a static library to an MFC-based program or to a non-MFC program for Windows written in C or C++, that makes calls to the Win32 API rather than to MFC classes. "

LabVIEW cannot directly link to a statically compiled .lib file but there is a workaround : Create a C or C++ DLL that links to this statically compiled .LIB file and call the DLL from LabVIEW. Since it is the C compiler that is linking to the .LIB file, LabVIEW does not know anyhing about the.LIB file but will just communicate indirectly with the .LIB via the C/C++ DLL.

Hope this helps,

Ankita

Message 2 of 6
(7,192 Views)
Hello Ankita,
 
 
Thank you for your response.  However, I'm a little confused.  Are you saying that if I were able to recompile the C++ .LIB file to a .DLL file then I could use LabView's "Call Library Function" VI?  I was not aware that LabView could call object methods without a "C" interface.
0 Kudos
Message 3 of 6
(7,188 Views)
Hi,
 
Please visit the "Using External Code with LabVIEW" manual for more information on calling and creating C++ Dlls to be called with LabVIEW.
 
Hope it helps,
Ankita 
0 Kudos
Message 4 of 6
(7,173 Views)

Hi Ankita,

Thank you for your assistance thus far, you have been a great help!

I do have one final issue to resolve.  I have been warned by colleges that LabView does not work well with externally allocated memory.  I am worried this would apply to objects created in a .dll.  The documentation I have read does not seem to address this issue directly.

QUESTION: How should I create objects from my library .dll file that will safely exist after exiting a "Call Library Function" VI?

For example, I would like to create a USBdevice object at the start of my LabView application that would exist until the program is exited.  I could then make calls to read/write methods as needed.  Otherwise, I will have to create and destroy a USBdevice everytime I communicate with my hardware via the device driver.  Constantly creating and destroying this object would be very inefficient.

Please advise.

-- Al Dugas

0 Kudos
Message 5 of 6
(7,159 Views)
What is generally meant that LV doesn't work well with externally allocated memory is that you cannot allocate an array in C and then give it to LV to use as a LV native array. It is similar to the memory issues you find in other language interop with Java, .NET, even device drivers.
 
What you can do is pass LV a handle to an external piece of memory (or class or whatever) and tell LV to treat it as an opaque handle. Just by passing it in as an int32, LV will simply hold onto the value and pass it back to the external code when you need. Thus you allocate it at the start and free it at the end - problem solved.
 
Do note that you are responsible for the cleanup of such external memory.
 
If you want to get even deeper on this issue, see my posting at the end of this thread http://forums.ni.com/ni/board/message?board.id=170&message.id=135715
 
0 Kudos
Message 6 of 6
(7,148 Views)