LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

What is the best way to add external C++ code to LabView 6.1?

I have various C++ class-based DLL's written with Visual Studio 6.0 and wish
to create instances of these C++ classes and call their methods in LabView
6.1. What is the best way to do this?

It seems based on the little reading I have done that there are two choices:

1. Wrap the C++ class as a simple COM control and use LabView's COM based
VIs to create a COM object and access the methods of various interfaces.

2. Wrap the C++ class methods as C functions and a "constructor" and
"destructor" C function to create and destroy an instance of the class. Then
use LabView's DLL call support.

Which is best? What direction is LabView going to take that better supports
the notion of C++ class libraries?

Thanks,

Te
rry
0 Kudos
Message 1 of 2
(3,572 Views)
You could also try using a CIN. This is a tool that LabVIEW provides for interfacing with external code.

The CINTools libraries of LabVIEW allow you to embed compiled C code into a particular Virtual Instrument (VI) using a CIN.

In order for LabVIEW to be capable of calling compiled functions of C from a running VI, the code must be loaded and unloaded into memory at the same time as the VI code itself. LabVIEW uses object code in the form of a .lsb file which is generated by the C compiler from the C source code using the ntlvsbm.mak file. This ntlvsbm.mak file is included in the CINtools directory in the LabVIEW folder. You also must create another .mak file which includes parameter definitions for the ntlvsbm.mak file and also includes a call to the LabVIEW .mak file.

The generic documentation for CINs only explains how to use them to call C compiled code from a LabVIEW VI. It shows several development environments such as Visual C++, but in essence it only allows the user to create .lsb files out of plain C source code ( .c ) through C compilers on those environments.

The question now is how can I create .lsb files from C++ native source code using a C++ compiler. Furthermore, how can I create a .lsb file from several C++ source code files (.cpp) and make calls to C++ functions from a VI using CINs? The following explains how to do this:

1) Drop a Code Interface Node (from the Advanced Subpalette of the Functions Palette) into the LabVIEW VI. Make sure to wire the inputs.
2) Right-click on the CIN and choose "Create.c File...", then in the file dialog box specify a "name.cpp" file name. (very important: use .cpp extension)
3) Then create a name.mak makefile (text file) and add the following lines :

name=name_of_cpp_file_without_the_extension
type=CIN
cinlibraries=Kernel32.lib
CINTOOLSDIR=path_to_cintools_directory
!include <$(CINTOOLSDIR)\ntlvsb.mak>

4) Go into Visual C++ and File>Open and open the .mak file. You can even Add the name.cpp file to the project to make it easier to edit. Select that name.cpp or open it as a text file in NotePad or and edit the prototypes of the CIN MgErr functions as shown below, adding extern "C" at the beginning of the line. extern "C" CIN MgErr CINRun(float64 *INPUT);3) Select Build.exe to create the "name.lsb" file. To import the .lsb into LabVIEW, right-click on the CIN and choose "Load Code Resource...". Then, choose the name.lsb file and it is ready to run!

If you want to use several C++ source code files with .cpp extensions, then compile them in Visual C++ and link them to name.cpp and create a .lsb by modifying the name.mak as follows:

name=name_of_cpp_file_without_the_extension
otherobj=other_cpp_files_BUT_USING_.obj_extension
type=CIN
cinlibraries=Kernel32.lib
CINTOOLSDIR=path_to_cintools_directory
!include <$(CINTOOLSDIR)\ntlvsbm.mak>

It's worth a try? I have also heard of using clusters to represent classes, so you could check that out.
J.R. Allen
0 Kudos
Message 2 of 2
(3,573 Views)