LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

dll, matlab an LadVIEW

I encounter the same problem with a Matlab DLL in LabView. Any progress on this issue?
 
Thanks,
Gudrun
0 Kudos
Message 31 of 86
(3,971 Views)

Hi,

Sorry it took me so long to reply - I gave birthSmiley Happy

About the MCR - the Mathworks specifically forbid posting it on the web (I don't know why) and it's 85 Mb so I can't send it by mail. Maybe you can get it from another source (if you still want it at all).

About the example wrapper file - it's there in the zip. It is the c++ files.
There is also a good example in the mathworks: http://www.mathworks.com/support/solutions/data/1-PM4OX.html?1-PM4OX that gives an example of loading a matlab dll file in MSVC 6. To create a dll all you have to do is choose dll instead of exe in your MSVC project.

Hope this helps,

Danielle

"Wisdom comes from experience. Experience is often a result of lack of wisdom.”
― Terry Pratchett
0 Kudos
Message 32 of 86
(3,960 Views)
Hi Danielle,
 
Congratualtions on the new baby!
 
I understand entirely about the MCR. Anyway, I have moved toward adopting the mathscript feature in LV8.2. Seems to do the trick. And the function libraries in the pro development version are quite extensive. 
 
To some extent I am still curious about the DLL calls so thank you for the link to the app note, I will check it out.
 
Zador 
0 Kudos
Message 33 of 86
(3,965 Views)

hi,

Danielle, congratulations on your new baby! As a coincidence, I myself just am back at work from giving birth tooSmiley Very Happy

The extensive LabView code the module using the Matlab-generated DLL will be integrated in, is not easily transferred to a LabView version beyond 7.0. Also we don't want to install Matlab on every computer running the programm. So I am eager to solve the problem that the code only runs once and then crashes LabView.

Danielle, did you succeed in using the code provided by gnilsson?

Thanks for sharing your experiences!

Gudrun

0 Kudos
Message 34 of 86
(3,960 Views)

Hi,

No, I didn't succeed in using the code of gnilsson. It didn't compile. I solved the problem by splitting the function into init, func and terminate. the init runs when the program starts; func is activated when user wants it; terminate runs when user presses quit. This allows the user to use the function more than once.

Good luck!

"Wisdom comes from experience. Experience is often a result of lack of wisdom.”
― Terry Pratchett
0 Kudos
Message 35 of 86
(3,947 Views)
Hi Danielle

I tried using the same DLL with along with the VIs provided by you in Labview 8.2 and it does not work. Still, call function node reports an error. Are there any additional considerations to be taken care of when using LV 8.2?

Regards
NRK
0 Kudos
Message 36 of 86
(3,811 Views)
I am trying to get a MATLAB compiled DLL to work in LabVIEW.  I have monitored many of the discussion but I don't see anyone having the same problem I am that was resolved.  The problem appears to be when the <library> terminate is called along with the MCR terminate function.  It doesn't really seem to terminate.  Her is a snippet of my code.  I have broken the wrapper into 3 parts:  Init, Calculate and Uninit.    Then in LV I have 3 calls to the call library node.  First the init, then a loop to call calculate (vilineWidth) and finally terminate when stop is clicked.  If I start fresh - delete the directory created by the MCRInitialize (\cviDLL_mcr) I can successfully call the Init and calculate as many times as I want.  When I click stop it "appears" to stop.  Problem is that the <library>Terminate does not return a value.  If I try to re-run then I get an error when the mclInitializeApplicationfunction is called.  If I exit LV and manually blow away the _mcr directory and re-run I can get back to being able to call calculate.  If I try to blow away the directory WITHOUT closing LV is says a file is in use and cannot do it.  This would seem to suggest that the Terminates are not functioning properly.  Any thougts??
 

LLCVICALC_API

int CVIMatlabInit(void)

{

 if(!mclInitializeApplication(NULL,0))

{

//std::cerr << "Could not initialize MCR" << std::endl;

return -5;

}

if (!cviDLLInitialize()){

//fprintf(stderr,"Could not initialize the library.\n");

return -6;

}

return 0;

}

DLLCVICALC_API

int CVIMatlabTerminate(void)

{

bool bReturn = false;

cviDLLTerminate();

cviDLLTerminate();

bReturn = mclTerminateApplication();

if ( bReturn == true )

return 0;

else

return -7;

}

DLLCVICALC_API

int VIlineWidth(void){

int len = 0;

mxLogical tf[1] = {

true};

mxChar filetoprocess[13]={

's','a','m','p','l','e','A','.','t','i','f','f','\0'};

mwArray mwMatlabOutput;

try {

//len = strlen(in1);

mwArray inMatlabData(1, 13, mxCHAR_CLASS);

inMatlabData.SetCharData(filetoprocess, 13);

//output array

mwArray inpFlag(1,1,mxLOGICAL_CLASS);

inpFlag.SetLogicalData(tf,1);

cviDLL(1,mwMatlabOutput,inMatlabData,inpFlag);

}

catch (const mwException & e) {

return -3;

}

catch(...) {

return -4;

}

return 0;

}

0 Kudos
Message 37 of 86
(3,401 Views)
I am trying to get a MATLAB compiled DLL to work in LabVIEW.  I have monitored many of the discussion but I don't see anyone having the same problem I am that was resolved.  The problem appears to be when the <library> terminate is called along with the MCR terminate function.  It doesn't really seem to terminate.  Her is a snippet of my code.  I have broken the wrapper into 3 parts:  Init, Calculate and Uninit.    Then in LV I have 3 calls to the call library node.  First the init, then a loop to call calculate (vilineWidth) and finally terminate when stop is clicked.  If I start fresh - delete the directory created by the MCRInitialize (\cviDLL_mcr) I can successfully call the Init and calculate as many times as I want.  When I click stop it "appears" to stop.  Problem is that the <library>Terminate does not return a value.  If I try to re-run then I get an error when the mclInitializeApplicationfunction is called.  If I exit LV and manually blow away the _mcr directory and re-run I can get back to being able to call calculate.  If I try to blow away the directory WITHOUT closing LV is says a file is in use and cannot do it.  This would seem to suggest that the Terminates are not functioning properly.  Any thougts??
 

LLCVICALC_API

int CVIMatlabInit(void)

{

  if(!mclInitializeApplication(NULL,0))

{

//std::cerr << "Could not initialize MCR" << std::endl;

return -5;

}

if (!cviDLLInitialize()){

//fprintf(stderr,"Could not initialize the library.\n");

return -6;

}

return 0;

}

DLLCVICALC_API

int CVIMatlabTerminate(void)

{

bool bReturn = false;

cviDLLTerminate();

cviDLLTerminate();

bReturn = mclTerminateApplication();

if ( bReturn == true )

return 0;

else

return -7;

}

DLLCVICALC_API

int VIlineWidth(void){

int len = 0;

mxLogical tf[1] = {

true};

mxChar filetoprocess[13]={

's','a','m','p','l','e','A','.','t','i','f','f','\0'};

mwArray mwMatlabOutput;

try {

//len = strlen(in1);

mwArray inMatlabData(1, 13, mxCHAR_CLASS);

inMatlabData.SetCharData(filetoprocess, 13);

//output array

mwArray inpFlag(1,1,mxLOGICAL_CLASS);

inpFlag.SetLogicalData(tf,1);

cviDLL(1,mwMatlabOutput,inMatlabData,inpFlag);

}

catch (const mwException & e) {

return -3;

}

catch(...) {

return -4;

}

return 0;

}

0 Kudos
Message 38 of 86
(3,401 Views)
I have monitored this thread plus many others on trying to get a MATLAB dll to work from LV.  I am close but it appears that the terminate functions (both for the library and the MCR) are not terminating properly.  What I have is a wrapper DLL that has 3 functions an Init, a calculate, and a Uninit.  I have 3 call library nodes in my VI and on a fresh start (I delete the MCR created directory _mcr) and it work fine until the terminate.  I call the initializes and the MATLAB run-time creates the _mcr directory.  I can call my calculation routine as many times as I want from a loop, an it appears to exit (terminate) normally.  The problem is when I re-run the VI the intialize fails.  The only work around is to close LV and delete the _mcr directory.  I cannot delete the directory without LV being closed because it says a file is in use.  This leads me to believe it is a terminate issue.  Any thoughts??
 

Attached is a code

 

John

0 Kudos
Message 39 of 86
(3,394 Views)
Hi,
 
I'm also having problems with MCR terminate fuction. It seems that the only way to really terminate MCR is by closing LabView completly. Any solution to this?
 
0 Kudos
Message 40 of 86
(3,143 Views)