1

I would like to execute a Labview VI through ActiveX in Matlab.

I use the following commands:

e=actxserver('LabVIEW.Application');
vipath='C:\DATA\Labview\test.vi';
vi=invoke(e,'GetVIReference',vipath);
vi.Run;

This works correctly and the VI is seen to execute on its front panel. However, Matlab keeps waiting until the VI has terminated. I want Labview to run the VI silently, without telling Matlab (through ActiveX) to wait.

How can a VI be executed without keeping ActiveX busy ? Is there a standard way to do so ? (I assume there should be, given how multitask-oriented Labview is - which is not the case of Matlab in its standard form).

CharlesB
  • 86,532
  • 28
  • 194
  • 218
calvin tiger
  • 391
  • 2
  • 7
  • 18

2 Answers2

1

You can either:

  • Launch LabVIEW.exe as a process, specifying VI as argument (search help for this). There is for sure a way to tell Matlab to not wait for end of process execution
  • Run the VI dynamically, using VI server, inside a launcher VI, and have Matlab call the launcher VI. The latter will return immediately after calling your VI, and Matlab will not wait for your main VI to end.
CharlesB
  • 86,532
  • 28
  • 194
  • 218
  • Actually, I would like to do it through the VI server (which is what the code does, I believe). I was told that I could set the "Wait Until Done" parameter of the "Run" method to False, but unfortunately I didn't manage to access this parameter through Matlab (even though I could do it from inside Labview). The Run method of the vi object is listed as: "Run(handle, Variant(Optional))" – calvin tiger Feb 16 '12 at 11:08
  • There is a related (although more general) question with more details on this issue on this forum post: http://forums.ni.com/t5/LabVIEW/Different-ActiveX-methods-appear-when-referencing-a-VI-inside-or/td-p/1879185 – calvin tiger Feb 16 '12 at 11:14
  • Oh you mean wrapping the VI that I want to call in a caller VI that sets the "Wait Until Done" parameter, and running the caller VI from Matlab ? It's a workaround, but it will definitely solve my problem :) Thanks for the idea ! – calvin tiger Feb 16 '12 at 11:40
1

I finally found the answer (thanks to smercurio_fc on the NI forum):

To run the VI in the background (without waiting until done):
vi.Run(1);

To run it and wait until its execution is complete:
vi.Run(0);
or
vi.Run;

In the background execution mode with vi.Run(1), execution can be interrupted with vi.Abort. During execution, input and output values can be changed with vi.SetControlValue and vi.GetControlValue.
For instance, to get the value of a numerical control 'z' during execution:
vi.GetControlValue('z')

calvin tiger
  • 391
  • 2
  • 7
  • 18