LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

how to connect matlab with CVI?

I want use some function of the matlab in CVI, and I utilize the ActiveX method, the matlab can be active, but the matlab command can not be executed?
what is the matter? My matlab is installed after the installation of CVI.
Dongsheng Zhao
North China Electronic Power Univ.
zds_hd@yahoo.com.cn
0 Kudos
Message 1 of 9
(5,485 Views)
Hello Zhao,

For a starting point on controlling Matlab from CVI using ActiveX I would suggest the matlab shipping example. It can be found under the CVI program directory in the following location:

C:\Program Files\National Instruments\CVI71\samples\activex\matlab\matlabdemo.prj

Scott Y
NI
0 Kudos
Message 2 of 9
(5,472 Views)
Scott Y
Thank your answer.
I think the problem is not easy to be solved only follow the example code.
1)The .fp file in the example code is generated in one version of the matlab software,it not work well for other version;
2)My matlab version is 6.5, and Labwindows is 7.0, when I execute the code, the comand window of matlab is actived by the code, but there is always the error of sending Matrix to Matlab, this is my question, and I want to know how to solve it.
Dongsheng Zhao
North China Electronic Power Univ.
zds_hd@yahoo.com.cn
0 Kudos
Message 3 of 9
(5,419 Views)

Hello toidi,


1) So I would suggest, if you haven't already, upgrading your runtime engine to CVI 7.1.1. The CVI runtime engine is backwards compatible so you will still be able to build you applications in CVI 7.0.

2) Once you do this, recreate the Matlab instrument. Remove the current Matlab instrument and recreate the Matlab Automation Server Type Library by going to Tools >> Create ActiveX controller. The name of the Matlab instrument will be Matlab Application Type Library. Save the newly created ActiveX controller with the same name as the previous one (as in, just replace the one that is already in the shipping example directory with the newly created one).

3) Change the matlabdemo.c launch callback to read
stat = MLApp_NewDIMLApp (NULL, 1, LOCALE_NEUTRAL, 0, &hMatlab);
instead of
stat = MLApp_NewDIMLApp (NULL, &hMatlab);

4) Open the source code for the Matlab instrument and search and replace ALL instances of &MLApp_IID_DIMLApp with &IID_IDispatch.


After doing this, I was able to run the Matlab example with Matlab 6.5 R13 and CVI 7.1.

Let me know how this goes. Thanks.

Wendy L
LabWindows/CVI Developer Newsletter
0 Kudos
Message 4 of 9
(5,405 Views)
Wendy L
THANK YOU VERY MUCH!
Your suggestion works very well,and thank you again.
But I do not know why I shoule modify like that, can you tell me?
Dongsheng Zhao
North China Electronic Power Univ.
zds_hd@yahoo.com.cn
0 Kudos
Message 5 of 9
(5,378 Views)
Hello toidi,

Since the Matlab Automation Server's interface changes between different versions of Matlab, recreating the ActiveX controller is necessary. Since parameters were added to the NewDIMLApp function, appropriate modification has to be made to any code using this function. Also, instances of &MLApp_IID_DIMLApp needs to be replaced with &IID_IDispatch for certain versions of Matlab since its automation server only seems to honor the IDispatch interface ID.

Thanks.
Wendy L
LabWindows/CVI Developer Newsletter
0 Kudos
Message 6 of 9
(5,362 Views)

I had used the method provided by Wendy L . However, after I searching and replacing ALL instances of &MLApp_IID_DIMLApp with &IID_IDispatch in matlabsrvr.c,another problem came:  82, 61   Undeclared identifier 'IID_IDispatchb'. So I defined the cosnt 'IID_IDispatchb'
with        const IID IID_IDispatchb=
               {
                  0x669CEC93, 0x6E22, 0x11CF, 0xA4, 0xD6, 0x0, 0xA0, 0x24, 0x58, 0x3C, 0x19
                };
Was it right?

After this replacing ,there was no error.However,when running,error came back. It can not link to matlab. What's wrong?! 

My matlab version is 6.5, and Labwindows is 7.0

0 Kudos
Message 7 of 9
(5,186 Views)

Hello icestar,

I would double check and make sure that you replaced all instances of  &MLApp_IID_DIMLApp with &IID_IDispatch instead of &IID_IDispatchb. The generated matlabsrvr.c code should not have references to &IID_IDispatchb.  After doing this, does the problem resolve itself?

Thanks

Wendy L
LabWindows/CVI Developer Newsletter
0 Kudos
Message 8 of 9
(5,168 Views)
to Wendy L
Thanks for your help.
Problem has been solved,
I mistook &IID_IDispatchb for &IID_IDispatch.
0 Kudos
Message 9 of 9
(5,161 Views)