How can you call a LabVIEW VI from MATLAB script?

Hey!
I was wondering if I could run a LabVIEW VI through a command/function in MATLAB. I don't want exchange of any data, or anything fancy. I just want to run the VI at a specific time through my MATLAB code. I looked up the net and found this:
e=actxserver('LabVIEW.Application');
vipath='c:\Documents\Test\test.vi';
vi=invoke(e,'GetVIReference',vipath);
vi.Run;
However, whenever I try to run this, I get the error
Error using
COM.LabVIEW_Application/GetVIReference
Invoke Error, Dispatch Exception:
Source: LabVIEW
Description: LabVIEW: Open VI Reference no
longer matches VIs in memory by filename. A
filename is no longer sufficient because the
full name of a VI now includes any owning
libraries.
Error in readColorVI (line 7)
vi=invoke(e,'GetVIReference',vipath);
Can anyone help me around with this error? From what I gather, it seems I need to provide something else along the path of the VI? If so, what is it? Is there any other way to do it?

 採用された回答

Ahmet Cecen
Ahmet Cecen 2018 年 3 月 28 日

1 投票

If you have them both installed this should just work:
!test.vi

5 件のコメント

Deepansh Bhatia
Deepansh Bhatia 2018 年 3 月 28 日
編集済み: Deepansh Bhatia 2018 年 3 月 28 日
Strangely enough, this command opens the specific VI but it doesn't run it. Is there any way to make it run automatically rather than just opening it?
Furthermore, it seems strange that MATLAB just opens the VI and doesn't run it, or return the control to any code following. It's like the script is stuck in an infinite loop.
Guillaume
Guillaume 2018 年 3 月 28 日
If I remember correctly there's an option under execution in the VI properties to have it run automatically when opened. Have you tried that?
Deepansh Bhatia
Deepansh Bhatia 2018 年 3 月 29 日
This idea worked! The VI now runs automatically when opened by MATLAB, but the script still doesn't execute the following code, until I specifically close the LabVIEW window. Is there any way in which the control returns to the statements after !test.vi?
Ahmet Cecen
Ahmet Cecen 2018 年 3 月 29 日
If this is windows, the following should work:
!start test.vi
Deepansh Bhatia
Deepansh Bhatia 2018 年 3 月 29 日
Awesome! Worked like a charm! Thank you so very much.

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

その他の回答 (2 件)

Stefano Franceschini
Stefano Franceschini 2018 年 9 月 7 日

0 投票

hi! i saw this code and I wanted to test it, but when I run the "e=actxserver('LabVIEW.Application');" line, and matlab shows me this error "Error using feval Server Creation Failed: Impossible to find the specific file.
Error in actxserver (line 86) h=feval(['COM.' convertedProgID], 'server', machinename, interface); " Does anyone know how to fix this issue?

1 件のコメント

Guillaume
Guillaume 2018 年 9 月 7 日
編集済み: Guillaume 2018 年 9 月 7 日
"Does anyone know how to fix this issue?"
Install LabVIEW.

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

NI_OS
NI_OS 2020 年 2 月 25 日

0 投票

You need LabVIEW & MATLAB on the same machine installed and licensed.
I'll tested it with LV2019SP1 & MATLAB R2019b:
e=actxserver('LabVIEW.Application');
vipath='C:\Users\NI\Desktop\test.vi';
vi=invoke(e,'GetVIReference',vipath);
!start C:\Users\NI\Desktop\test.vi
vi.Run;
This code works perfect for running a LabVIEW VI out of MATLAB.
See the LabVIEW test.vi attatched as a Snipped:

カテゴリ

タグ

質問済み:

2018 年 3 月 28 日

回答済み:

2020 年 2 月 25 日

Community Treasure Hunt

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

Start Hunting!

Translated by