LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Labview Calling DLL with 2D array input and output

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

 dll.jpg

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.

0 Kudos
Message 1 of 9
(8,488 Views)
May be both of the two methods have some problems.
0 Kudos
Message 2 of 9
(8,475 Views)
Have you looked at the examples that ship with LabVIEW or done a search on this site? If you open the Example Finder (Help -> Find Examples) and search for "DLL", open the "Call DLL" example. It has many examples of calling various datatypes, including one for 2D numeric arrays.
Message 3 of 9
(8,461 Views)
If you change the datatype of the 2D arrays to pointers (*A) instead of handles (**A), LabVIEW should not have any trouble with it.  If you want an example of this, check out the HDF5 library found here.
Message 4 of 9
(8,433 Views)

 


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.

 

 

Message Edited by rolfk on 05-26-2010 09:11 AM
Rolf Kalbermatter
My Blog
Message 5 of 9
(8,421 Views)

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

0 Kudos
Message 6 of 9
(8,396 Views)

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.

0 Kudos
Message 7 of 9
(8,389 Views)

can you add your labview file?

I don't succeed to understand how I return a variable that is type is array.

0 Kudos
Message 8 of 9
(4,804 Views)

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.

 

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 9 of 9
(4,784 Views)