LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

C++ module in labview

I have an issue here. I need to have C++ (or other low level language) to interface specially made equipments. A C++ developer is doing that. But I also need to have Labview control a group RF equipments. Over the years, we have built a big number programs. I would like to have these two different program together. I perfer to use Labview to call C++ module.
 
I looked Labview 8.5 and it seems possible to do that. An example is great.
 
Thanks,
Alex
0 Kudos
Message 1 of 7
(4,150 Views)
You can call C++ DLL functions with Labview by using the Call Library Node function.  See the attached example.  On the block diagram, double click on the Call Library function and you will see how to define the function to be called and its parameters.  The attached example calls the kernel.dll function to get file attributes.
- tbob

Inventor of the WORM Global
Message 2 of 7
(4,138 Views)
On Sep 5, 1:40 pm, Alex Chee <x...@no.email> wrote:
> I have an issue here. I need to have C++ (or other low level language) to interface specially made equipments. A C++ developer is doing that. But I also need to have Labview control a group RF equipments. Over the years, we have built a big number programs. I would like to have these two different program together. I perfer to use Labview to call C++ module.
> &nbsp;
> I looked Labview 8.5 and it seems possible to do that. An example is great.
> &nbsp;
> Thanks,
> Alex

A couple of possibilities. One Labview has a built in interface
to .net. LabWindows/CVI has external C/C++ compiler compatibility.
Hopefully others who have had more experience working with external C#
or C++ code can provide you with more information. If not the other
alternative is to talk to a National Instruments sales engineer.

Howard

0 Kudos
Message 3 of 7
(4,115 Views)
On Sep 5, 1:40 pm, Alex Chee <x...@no.email> wrote:
> I have an issue here. I need to have C++ (or other low level language) to interface specially made equipments. A C++ developer is doing that. But I also need to have Labview control a group RF equipments. Over the years, we have built a big number programs. I would like to have these two different program together. I perfer to use Labview to call C++ module.
> &nbsp;
> I looked Labview 8.5 and it seems possible to do that. An example is great.
> &nbsp;
> Thanks,
> Alex

Update, Labview also provides 3 other options for calling external
compiled code.
1. Using the command line with the System exec.vi.
2. Calling dynamic link libraries with the Call Libary Function Node.
3. Interfacing to compiled code using s Code Interface Node.

Howard

0 Kudos
Message 4 of 7
(4,112 Views)
The following link directs to a portion of the LabVIEW help which talks about calling text-based code in LabVIEW:

http://zone.ni.com/reference/en-XX/help/371361D-01/lvhowto/callcodefromotherproglangs/


-Bob
0 Kudos
Message 5 of 7
(4,092 Views)

Alex Chee wrote:
I have an issue here. I need to have C++ (or other low level language) to interface specially made equipments. A C++ developer is doing that. But I also need to have Labview control a group RF equipments. Over the years, we have built a big number programs. I would like to have these two different program together. I perfer to use Labview to call C++ module.
 
I looked Labview 8.5 and it seems possible to do that. An example is great.
 
Thanks,
Alex

There have been several suggestions but they all are not likely to work without some extra wrapper DLL code or similar thing.
 
Let's look at the different solutions:
 
1) .Net: You likely will need to wrap your unmanaged C++ library into some managed .Net component to be calleble through LabVIEWs .Net interface.
 
2) ActiveX: The same as above. C++ can be used to create ActiveX components but is not the same. So you likely will have to create an ActiveX interface for your C++ library.
 
3) Call Library Node: This node can only call standard C exported functions (or globally defined C++ functions aside from the name mangling that occures. C++ libraries however are mostly written as a collection of objects with methods and possibly public data members. The Call Library Node can't directly interface to that. You would have to tell your C++ programmer to provide standard C exported wrapper functions for all the object methods you need and also the constructor and destructor for all opjects.
 
A little example kept simple for this purpose:
#include <iostream>
using namespace std;

class CRectangle {
    int x, y;
  public:
    void set_values (int,int);
    int area () {return (x*y);}
} * PRectangle;

void CRectangle::set_values (int a, int b) {
  x = a;
  y = b;
}
:
For this your college would have to add this extra stuff to his library (in theory! my C++ is not that great and this likely contains some syntax errors):
extern "C" {
  PRectangle CRectangle_cnstructor(void);
  void CRectangle_destructor(PRectangle o);
  void CRectangle_set_values(PRectangle o, int a, int b);
  int  CRectangle_area(void);
}
PRectangle CRectangle_cnstructor(void) {
    return new CRectangle;
}
void _set_values(PRectangle o, int a, int b) {
    o->set_values(a, b);
}
int CRectangle_area(PRectangle o) {
    return o->area();
}
void CRectangle_destructor(PRectangle o) {
    delete o;
}
This is really just some code put together quickly to give you an idea about how to go about this and should not be taken as the ultimate guide how to wrap C++ code to be callable from standard C or in this case the LabVIEW Call Library Node.
 
Rolf Kalbermatter
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 6 of 7
(4,080 Views)
Kernel32.dll is not a C++ dll, but a C dll. You can call it in C++. It might also very well be that it's build using c++, but the functions are exported so C can call them.


A C++ dll has charaters in the function name that indicate (to the c++ compiler) what it's class and parameters are. It will look something like: &$%&&&*3#$33CPPFunction##^%&*%* (this format will depend on the used c++ compiler and version). This is the name mangling Rolf is talking about. LabVIEW will not be able to interface with that.


If you need to do that, the easiest way would be to make a wrapper in c++ that does export the functions so c (and LabVIEW) would understand it. Or ask the developers to compile the dll again.


Regards,


Wiebe.
0 Kudos
Message 7 of 7
(4,056 Views)