LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

CVI and Matlab Automation Server Issues

I am looking to use a the Matlab Automation sever to run a few Matlab functions that cannot be run outside of the Matlab environment from within my CVI project.  I am using Matlab 2012b and CVI2013.  Right now I created a very simple CVI project to test out functionality before throwing it into my more complicated project.

 

I seem to havve no problem lauching the Matlab command prempt and I can manually type in functions and execute them just as though I were had all of Matlab itself open.  After this I have two problems:

 

1) When I use MLApp_DIMLAppExecute it does not seem to work for to run a script.  I give the following Matlab command:

run('<path>\<script.m>');

 

Now if I type that same command into the comand prompt that CVI opened, it works just fine.  Also I have tried doing something like "d = 2;" for the command and then if I type "d" into the command prompt it will return "2" so I'm not sure what is happening there.

 

2) When I use MLApp_DIMLAppQuit, it closes the command prompt but does not kill the Matlab process and so if I use MLApp_NewDIMLApp again it doesn't actually create anything new and a command prompt never pops up.

 

Below I have included my source code for my simple example that I've been playing with.

 

#include "matlabsrv2012b.h"
#include "main.h"

static CAObjHandle hdlMatlab = 0; int main (int argc, char *argv[]){ HRESULT hStatus = 0; char* returnValue = NULL; hStatus = MLApp_NewDIMLApp(NULL,1,LOCALE_NEUTRAL,0,&hdlMatlab); hStatus = MLApp_DIMLAppExecute(hdlMatlab,NULL,"run('C:\CoreEH\Tools\EH_Common_Workspace_Channel_Generator\Matlab_Fcns\main.m');",&returnValue); hStatus = MLApp_DIMLAppQuit(hdlMatlab,NULL); return 0; }

 

Any input on what might be causing these problems would be great.  Thanks in advance.

0 Kudos
Message 1 of 2
(4,527 Views)

So looking into it more, probably 1) has been solved.  As you can see my path just had single '\' in it from doing a copy/paste from explorer so I just had to add another '\' before them.

 

As far as problem 2) goes - I still cannot figure this one but I have found a work around... ish.  I am just using the execute command function to send the "exit;" command to Matlab.  This completely closes it out but then throws an error at me.  In part of a function I have it looking to see if "exit" is the command and then ignore the corresponding error.  A little crude but it works for the time being.

 

Hopefully that helps anyone else that might run into these problems.  I'd still like to figure out how to close it down properly.

0 Kudos
Message 2 of 2
(4,517 Views)