How can a Labview VI be run as a background task through an ActiveX call ? (without keeping ActiveX busy)

拟墨画扇 提交于 2019-12-31 04:37:32

问题


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).


回答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.



回答2:


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')



来源:https://stackoverflow.com/questions/9299817/how-can-a-labview-vi-be-run-as-a-background-task-through-an-activex-call-with

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!