LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

import shared library to use matlab DLL

Hi all,

 

I have a simple Matlab code, as stated below:

function y = foo(x)
y = x+1;

 

and I've used Matlab's deployment tool (deploytool) to generate DLL and .h files for this function.

 

The problem is that when I'm trying to use LabVIEW's Import Shared Library tool, I'm not being able to use the generated DLL and the error is that the functions can not be found on the header file, as can be seen on the attached .png file.

 

The dll and header file are atatched in the .zip file below.

 

Can you succeed in using them to build a VI?

 

Any help would be greatly appreciated.

 

Thank you very much in advance.

 

Best regards!

Download All
0 Kudos
Message 1 of 5
(4,251 Views)

I'm afraid you can't just import your MatLab DLL in LabVIEW. MatLab expects mxArray pointers as in- and outputs.

You can't handle mxArray types in LabVIEW. I suggest you to build a wrapper DLL around your MatLab DLL that exports your MatLab function with the appropriate signature as well as the functions to initialize and terminate the MatLab Runtime. You can use the following function signatures for you wrappers:

 

extern "C" int32 wrapFooInitialize(void);

 

extern "C" void wrapFooTerminate(void);

 

extern "C" int32 wrapFoo(float64 *y, float64 x);

 

The first two functions just forward the calls to fooInitialize() / fooTerminate() . Be careful to call Initialize() before and Terminate() after your MatLab function, otherwise LabVIEW will crash.

The third one, wrapFoo() has to construct the mxArray *prhs[] from x and extract the resulting y from mxArray *plhs[].

You have to consult the MatLab documentation on how to deal with mxArray types in C. Unfotrunately I don't remember the details and don't have MatLab installed. All I remember is that it isn't much fun at all...

0 Kudos
Message 2 of 5
(4,236 Views)

That's not completely true.  If you know what the data will look like leaving the function, and can manipulate it from an array of U8s into what you want, it's manageable.

 

For instance:

  If you know your data size will be 8 32-bit pieces of data (easy case), you want to initialize an array of U8s, 32 wide, and feed that into the function.  Afterwards, you will need to change the data to what you want, but if you know the structure, it shouldn't be too bad.  This also works with clusters, and arrays of clusters of arrays (just get the structure size, and it will do the rest)

0 Kudos
Message 3 of 5
(4,229 Views)

Britoa:

 

Are you saying we can construct an mxArray structure within LabVEW and then send it to a MatLab DLL?

 

An example would be great.  The mxArray struct is confusing me.

http://www.medicollector.com
0 Kudos
Message 4 of 5
(3,794 Views)

As it turns out, a solution to the mxArray problem is to have your Matlab function use bounded arrays (eg fixed length) instead of unbounded. 

 

Fixed length arrays do not use the mxArray struct.  They are standard pointers which LabVIEW can directly convert to LabvIEW array datatypes.

http://www.medicollector.com
0 Kudos
Message 5 of 5
(3,744 Views)