From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

dll, matlab an LadVIEW

How do I call a MATLAB Compiler generated DLL from LabVIEW. It have pointer
as input and output.
0 Kudos
Message 1 of 86
(14,067 Views)
Use the call library function. It's fairly easy to do. But, you can
call MATLAB scripts from within Labview (provided MATLAB is installed on
that machine). Look for the formula node function, and the MATLAB
script node is right next to that.
0 Kudos
Message 2 of 86
(14,006 Views)
Kevin Mescher wrote in message
news:39AA5B7B.C4708F6A@vt.edu...
> Use the call library function. It's fairly easy to do. But, you can
> call MATLAB scripts from within Labview (provided MATLAB is installed on
> that machine). Look for the formula node function, and the MATLAB
> script node is right next to that.

I can't get 'call library function' to call MATLAB dll either.

I am trying to do very similar thing as Martin. I want to be able to call
MATLAB Compiler generated dll shared library without invoking MATLAB
(otherwise I would have use the MATLAB script node). I thought this will
allow me to develop my algorithm in MATLAB, then packaged it in dll and use
it in LabVIEW without needing MATLAB.

Because MATLAB dll has input/ output ar
gument in mxArray format, I don't
know how to setup 'call library function' to use mxArray. I tried using
pointers and array in 'call library function', but I got the error message
that the file is not a 32bit dll.

Do you have an answer to using and setting up 'call library function' with
MATLAB Compiler generated dll stand-alone shared library?
0 Kudos
Message 3 of 86
(14,006 Views)
As the former request, I also like to use labview-call-library functions to interface matlab-c-compiled codes instead of script nodes from within Labview. The problem is: I generate the C codes, export files and dlls, then I try to set-up my VI-call-library function, but either an error message or a labview shut-down occurs.
Is there in the community anyone who has already solved such a (similar) problem?
Please note: everything runs with windows2000, I actually use MATLAB v5.3 (MSVC++ compiler) and LabVIEW v6.1. Matlab codes have real 2D matrices as input and output.
0 Kudos
Message 4 of 86
(14,006 Views)
Hey andrea,

I have the same exact problem as you, but have been unable to resolve this issue. Have you or anyone else been able to run a .dll compiled Matlab function from LabVIEW? If so, I and many others would appreciate some insight!
0 Kudos
Message 5 of 86
(14,006 Views)
Have any of you been able to resolve this issue? I need a place to get started in solving this problem. If any of have a template for a wrapper file or an example of a wrapper file that interfaces with C and labview it would help me. I'm going to be using lots of arrays for complex data, I would be willing to send you whatever I write when I finish.
0 Kudos
Message 6 of 86
(14,006 Views)
I'm sure many of you have resolved this MATLAB issue. Finally, I was able to run my MATLAB generated DLLs from LABVIEW. I had to create a wrapper in C to interface the two programs, since my LABVIEW program used type double and MATLAB used type MxArray. Mathworks Note 27671 shows how to create MATLAB DLLs and reference them in C. Two other documents on the National Instruments site show how use DLLs created in C or C++ with LABVIEW. They are:

"Writing Win32 Dynamic Link Libraries(DLLs) and calling them from LABVIEW"
"How to build a DLL with Visual C++"

In the end I had to create 2 DLLs, one from MATLAB and another from Visual C++ (created by compiling the wrapper file to a .DLL file). I've cut & pasted a simple wrapper file below. This simple template with the documents referred to above should answer most questions. To find explanations of matlab functions used such as mxCreateDoubleArray, refer to:

http://www.mathworks.com/access/helpdesk/help/techdoc/apiref/apiref.shtml

Good luck
-Daidipya


// dllarraytest.cpp : Defines the entry point for the DLL application.
//

#include "stdafx.h"
#include "foolib2.h"
#include "matlab.h"
#include


__declspec(dllexport) double wrapper_main(double *,double *,double *,double *,unsigned long);
void fill(double *,double *,int);

BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}


__declspec(dllexport) double wrapper_main(double *in1,double *in2,unsigned long size){


mxArray *in1_ptr,*in2_ptr,*out1_ptr,*out2_ptr;

/* Create an mxArray to input into mlfFoo */
in1_ptr=mxCreateDoubleMatrix(size,1,mxREAL);
in2_ptr=mxCreateDoubleMatrix(size,1,mxREAL);
/*copy values from double array to mxArray*/
fill(mxGetPr(in1_ptr),in1,size);
fill(mxGetPr(in2_ptr),in2,size);

/* Call the library initialization function */
foolib2Initialize();
/* Call the implementation function (the DLL created by foo2.m)*/
out1_ptr = mlfFoo2(&out2_ptr,in1_ptr,in2_ptr);
/* Call the library termination function */
foolib2Terminate();

/* The return value from mlfFoo is an mxArray so we must extract the data from it */
fill(in1,mxGetPr(out1_ptr),size);
fill(in2,mxGetPr(out2_ptr),size);

/*this does not work, memory that I allocated in C would cause
labview to crash*/
//memcpy(out1,mxGetPr(out1_ptr), sizeof(double)*size);
//memcpy(out2,mxGetPr(out2_ptr), sizeof(double)*size);

return size;

}

/* subroutine for filling up data */
void fill(double *out,double *in,int size)
{
int i;
/* you can fill up to max elements, so (*pr)<=max */
for (i=0; i < size; i++)
out[i]=in[i];
}
Message 7 of 86
(14,006 Views)
Hi....i had the same problem and I worked out a complete example...hope it helps. The example and its instructions are in the attached pdf file.

Good luck

Alberto
0 Kudos
Message 8 of 86
(14,006 Views)
Hi,
I had your same problem and so I have followed your instruction, but the instruction line mbuilder, that you wrote in pdf file, give me this error:
operands of = have illegal types `pointer to incomplete struct mxArray_tag defined at c:\matlab6p5\extern\include\matrix.h 162' and `int'
Have you some idea to solve my problem??
Thanks in advance, Ilaria.
0 Kudos
Message 9 of 86
(14,006 Views)

Does anyone have further insight in this problem, especially with compiling DLL's from MatLab7?

The example given by Aesteban in dllmatlablabview.pdf does not seem to be fully applicable to Matlab7.2.    Some of the switches for the Matlab compiler are not valid anymore and I can not find the header file "matlab.h".

Is it still neccessary to use a wrapper function to allow the C implementation of a Matlab *.m function?
 
Any comments will be appreciated.
Thanks
ChrisH
0 Kudos
Message 10 of 86
(13,498 Views)