LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to write a C wrapper dll to export Matlab dll functions so that LabVIEW Call Library Function Node can use it?

Hello LabView developers,
 
I used LabVIEW to call Matlab m script to implement matlab MPC successfully. I wanted to use Matlab compiler to compile the matlab m script function into a c shared library .dll so that LabVIEW can call it without requiring Matlab installed on the PC.
 
I used MatLab R2007b with matlab compiler. I was able to generate a C shared library dll set successfully using mcc command.
 
However, from the header file, I see that the inputs and outputs of the function prototype are in mxArray. I need to change this data type to whatever that LabView Call Library Function Node can recognize.
 
I have followed a few examples in the forum, but none of them went through.
 
I use LabView 8.5. I have Microsoft Visual C++ Version 6 and Microsoft Visual Studio 2005. The compiler is in C++. Should I use a C compiler only to generate the C wrapper dll so that Labview can recognize it in the Call Library Function Node?
 
If anybody has gone through this successfully, I would like to learn from you on how to do it.
 
Thanks,
 
Kimberly
0 Kudos
Message 1 of 5
(6,357 Views)

@yw wrote:
 I wanted to use Matlab compiler to compile the matlab m script function into a c shared library .dll so that LabVIEW can call it without requiring Matlab installed on the PC.

They would still need to install the Matlab Component Runtime in order to use the DLL, so I don't know if that changes your situation.
0 Kudos
Message 2 of 5
(6,352 Views)


@yw wrote:
Hello LabView developers,
 
I used LabVIEW to call Matlab m script to implement matlab MPC successfully. I wanted to use Matlab compiler to compile the matlab m script function into a c shared library .dll so that LabVIEW can call it without requiring Matlab installed on the PC.
 
I used MatLab R2007b with matlab compiler. I was able to generate a C shared library dll set successfully using mcc command.
 
However, from the header file, I see that the inputs and outputs of the function prototype are in mxArray. I need to change this data type to whatever that LabView Call Library Function Node can recognize.
 
I have followed a few examples in the forum, but none of them went through.
 
I use LabView 8.5. I have Microsoft Visual C++ Version 6 and Microsoft Visual Studio 2005. The compiler is in C++. Should I use a C compiler only to generate the C wrapper dll so that Labview can recognize it in the Call Library Function Node?
 
If anybody has gone through this successfully, I would like to learn from you on how to do it.
 
Thanks,
 
Kimberly


I'm not sure what type mxArray would have in C syntax. I would guess however that Matlab would support datatype parameters that are more or less common standard C datatypes. Otherwise the whole Matlab DLL story wouldn't make that much sense I think.

Rolf Kalbermatter
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 3 of 5
(6,330 Views)

Hi Kimberly,

The only datatypes supported are the standard types listed as options in the call library function.
Workaround is to use the Matlab® node function but you would need to purchase a  license or write a wrapper code to convert the datatype to a standard one, as you have tried.

I see that you have tried a few examples on the discussion forums, but there was a very extensive discussion about this exact application on the forums, with some user success:

http://forums.ni.com/ni/board/message?board.id=170&message.id=29793&view=by_date_ascending&page=1

I do like the example on MatLab's ® website: http://www.mathworks.com/support/solutions/data/1-PM4OX.html?1-PM4OX

Unfortunately, this is just a proprietary format that MatLab ® has and a lot of users are having the similar issue.  It seems that there is no easy workaround, and at NI, because we have no MatLab ® software, I cannot test this out.  Due to the variances in applications, MatLab ® versions, etc. its just a bit difficult.

 

 

0 Kudos
Message 4 of 5
(6,288 Views)


@TMC-NI wrote:

Unfortunately, this is just a proprietary format that MatLab ® has and a lot of users are having the similar issue.  It seems that there is no easy workaround, and at NI, because we have no MatLab ® software, I cannot test this out.  Due to the variances in applications, MatLab ® versions, etc. its just a bit difficult. 

I'm sure there is a Matlab license somewhere at NI Smiley Very Happy. Anything else would be very strange.

But probably not for the support people and I fully agree, it is not the task of NI technical support to dig into these things and provide ready made solutions. The Call Library Node supports just about any basic standard C datatype (and all LabVIEW types too) and if there is software that thinks it needs proprietary datatypes then it is not NI's task to teach the user how to translate between this datatype and some more generic C datatype to  be implemented in a DLL wrapper.

NI already supports connection to Matlab through the script node for quite some of Matlabs datatypes and also an environment to run some of the Matlab scripts in its own environment. And there are third party libraries and Toolkits out there to yet again connect to Matlab in even other ways (Active X, etc.)

Rolf Kalbermatter


Message Edited by rolfk on 01-24-2008 07:19 AM
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 5 of 5
(6,278 Views)