How to create dll in Matlab to be used in Labview

21 ビュー (過去 30 日間)
Jong-Hwan Kim
Jong-Hwan Kim 2012 年 11 月 12 日
コメント済み: Michele 2025 年 2 月 11 日 14:23
Hi all,
I have problem with converting m-file in Matlab to dll file to be used in Labview. I used MCC to create dll from which Labview cannot find inputs and outputs. And is there any way to convert m-file to be used in Labview except using Matlab node due to its slow calculation speed? Thank you in advance.

採用された回答

Kaustubha Govind
Kaustubha Govind 2012 年 11 月 12 日
編集済み: Kaustubha Govind 2012 年 11 月 12 日
I'm not sure exactly what kind of interface LabVIEW requires, but this is how you need to interface with a DLL generated using MATLAB Compiler. Note that you will also need to install the MATLAB Compiler Runtime (MCR) on the machine that the DLL is being deployed upon.
I wonder of what you actually need is a standalone DLL (independent of the MCR) - in that case using MATLAB Coder might be the better option.
  4 件のコメント
Jong-Hwan Kim
Jong-Hwan Kim 2012 年 11 月 13 日
Thank you for your answer. I used MCR and MCC to create dll, finally DLL was successfully created, but Labview still cannot find inputs and outputs. :(
Kaustubha Govind
Kaustubha Govind 2012 年 11 月 15 日
Jong: How does LabVIEW "search" for interface exactly? Does it use the DLL header? Perhaps you might be able to ask NI's Technical Support team?

サインインしてコメントする。

その他の回答 (4 件)

David Roohy
David Roohy 2019 年 1 月 16 日

Michael Kaiser
Michael Kaiser 2012 年 11 月 16 日
I'm up against the same issue. I've created both C shared libraries and C++ shared libraries, but cannot use in LabVIEW. How is the MATLAB runtime invoked, initialized?

shubham kumar gupta
shubham kumar gupta 2021 年 2 月 4 日
編集済み: shubham kumar gupta 2021 年 2 月 4 日
GET A DLL FROM MATLAB:
mcc -v -B csharedlib:sumarray sumarray.m
create a scriptWrapper.c,scriptWrapper.h,scriptWrapper.def file[attached]
Now run below
mbuild -v sumarrayWrapper.c sumarray.lib LINKFLAGS="$LINKFLAGS /DLL /DEF:sumarrayWrapper.def" LDEXT=".dll" CMDLINE250="mt -outputresource:$EXE';'2 -manifest $MANIFEST"
now load this new scriptwrapper.dll in labview via import option, and add your old script.dll to this lvlib in labview
Always run loadFunction.vi before using your mainfunction.vi

Ricardo Gutierrez
Ricardo Gutierrez 2021 年 8 月 4 日
Dear Shubham Kumar Gupta:
I tested the code for preparing matlab DLL for labview, I have some questions, maybe you can help me. How can I create the Wrapper.c file when you have multiple inputs and multiple outputs?
  1 件のコメント
Michele
Michele 2025 年 2 月 11 日 14:23
The same way you can do for a 1 o 1 script.
This's my script:
function [SNR, PhaseNoise] = Measure_SNR_w_SBX(FullName, FigurePath)
close all
[...]
end
When you compile this script you'll obtain two functions with a signature like this:
extern LIB_MINE_API
bool MW_CALL_CONV mlxMeasure_SNR_w_SBX(int nlhs, mxArray *plhs[], int nrhs, mxArray
*prhs[]);
extern LIB_MINE_API bool MW_CALL_CONV mlfMeasure_SNR_w_SBX(int nargout, mxArray** SNR_dB, mxArray** PhaseNoise_mean, mxArray* FullName, mxArray* Figure_path);
You can use both to write your wrapper based on your experience with MatLab C API.. I'm not very familiar with it so I used mlf* variant.
To call/wrap this you need to do something like that:
int wmlfMeasure_SNR_w_SBX(char* FullName, char* FigurePath, double* SNR_dB, double* PhaseNoise_mean)
{
int result = 1;
mxArray* mFullName = mxCreateString(FullName);
mxArray* mFigure_path = mxCreateString(FigurePath);
int nargout = 2;
mxArray* mSNR_dB = NULL;
mxArray* mPhaseNoise_mean = NULL;
result = mlfMeasure_SNR_w_SBX(
nargout,
&mSNR_dB,
&mPhaseNoise_mean,
mFullName,
mFigure_path);
memcpy(SNR_dB, mxGetPr(mSNR_dB), sizeof(double));
memcpy(PhaseNoise_mean, mxGetPr(mPhaseNoise_mean), sizeof(double));
mxDestroyArray(mFullName);
mxDestroyArray(mFigure_path);
mxDestroyArray(mSNR_dB);
mxDestroyArray(mPhaseNoise_mean);
return result;
}
The only tricky part is to remember to use & when dealing with outputs parameters.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeC Shared Library Integration についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by