05-24-2010 06:34 AM
Hi all,
I have to call a dll which a 2D double array as an input and also a 2D double array as an output.The dll is made by me and written in c language , I need it to work efficiently.
If i define the program in labview like this
The 2 2Darrays sent into CLN were "Array data pointer",then how to define the function in c laguage? just like -----int myfunction (Parameter1,Parameter2,Parameter3,Parameter4)
If the function in the dll is defined like this int myfunction (double **A, int sx,int sy ,double **B,int ix,int iy),then what will the program in labview will be ?
sx ,sy ix ,iy are the array's size.
05-24-2010 07:12 AM
05-24-2010 09:44 AM
05-25-2010 07:30 AM
05-26-2010 02:10 AM - edited 05-26-2010 02:11 AM
ylongwu wrote:
If the function in the dll is defined like this int myfunction (double **A, int sx,int sy ,double **B,int ix,int iy),then what will the program in labview will be ?
sx ,sy ix ,iy are the array's size.
Your proposed prototype double ** seems to indicate that you want an array of pointers to the rows of the array. That is not how LabVIEW stores multidimensional arrays (nor how this is usually done in C for such arrays).
LabVIEW and most C libraries threat multi dimensional array as one single block of memory where the rows are located one after the other. So as DFGray has already pointed out you should use double * instead as datatype or since you create the DLL yourself and if it doesn't need to be compatible with other environments than LabVIEW change that altogether into:
typedef struct {
int32 dimSize1;
int32 dimSize2;
double elm[1];
} 2DDblArrRec, **2DDblArrHdl;
int myfunction (2DDblArrHdl A, 2DDblArrHdl B);
then change the Call Library Node parameters for the arrays to pass the array as Data Handle (the native LabVIEW datatype) and leave away the extra dimensions since they are already inside the handle structure.
Last but not least if you want to be very fancy you can even use NumericArrayResize() on the output handle to resize it to the correct size before filling in your information and leave away the Initialize Array function on the LabVIEW diagram.
05-27-2010 09:07 AM
Hello,
Thank you very much!With your help I have solved the problems now.
I finally defined the function as" int myfunction (double *A, int sx,int sy ,double *B,int ix,int iy)" and the program in Labvie is like the Picture above.
The dll was written in matalb, the function"mclInitializeApplication" in the dll ,it was very slow and can only be used once for one application.
So every time I want to use the dll once more i need to close "labveiw.exe" then restart "labview.exe", open the Labview program and run it.
Dou you have some suggestions ?
Maybe it should submit in the matlab website
05-27-2010 09:43 AM
It is helpful !
I have compiled a C-DLL that in turen calls Matlab DLL. The C-DLL is used by another program (Labview in my case, but I don't think it's matter).
In my C DLL header, I declare a function called "CDLLInit" and "CDLLClose", in which I respectively call MATLAB Initialize and Terminate functions.
I call this CDLLInit in the main program, before using any Matlab function embeded in the intermediate C-DLL, and I call CDLLClose before exit my main program, and that is it.
01-02-2018 08:04 AM
can you add your labview file?
I don't succeed to understand how I return a variable that is type is array.
01-03-2018 02:42 AM
mayaya ha scritto:
can you add your labview file?
I don't succeed to understand how I return a variable that is type is array.
As I already suggested in another thread, searching into LabVIEW examples you can find a vi "Call DLL.vi" which contains plenty of call examples with many LabVIEW data types, including multidimensional arrays.