From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
03-06-2007 02:32 PM
03-06-2007 04:16 PM
02-27-2019 09:19 AM
Hello,
Sorry for digging out this old thread, but it's most relevant to what I wanted to do that I could find.
I have a compiled .exe LabView program which has a slider GUI in it. I want to write some MATLAB code to do some calculation and eventually set the slider value, instead of human doing it.
The ActiveX examples I found are all writing data to Excel from LabView. Your project seems more similar to what I wanted to achieve here, especially with the line vi.SetControlValue('in',4).
My question is:
1) Would it work?
2) Is ActiveX the best choice?
3) Any simple example to start?
Thanks!
02-27-2019 11:08 AM
1) Maybe but it's almost certainly more complicated than you think
2) Almost never if there's an alternative
3) Yes:
LabVIEW actually has a node that lets you run MATLAB script directly. Here is a link to the help page on it, which points to two examples that ship with LabVIEW if you use the "Help-->Find Examples..." menu selection.
02-27-2019 01:56 PM
Hi Kyle,
The MATLAB program is actually complicated and uses external Java jars, so running it inside LabView may be tricky.
My plan is run the MATLAB program and the LabView program in individual .exe, and expose the slider from LabView on ActiveX so MATLAB can see and change it. I just couldn't find an example except the original post from this thread doing that.
02-27-2019 02:50 PM
Well, you have to activate the ActiveX server first if you haven't already.
I couldn't find MATLAB examples of using ActiveX to call LabVIEW, but this project using C code and this project with visual basic have some examples and you might be able to figure it out from that.
03-05-2019 09:56 AM
I feel like I am almost there. After activating the ActiveX server in a .vi, I can have MATLAB run the .vi with the following commands:
e = actxserver('LabVIEW.Application'); vipath = 'F:\Joe\LabView\test\called_by_matlab.vi'; vi=invoke(e, 'GetVIREference', vipath); vi.Run
"vi.Run" will launch the LabView editor. Even thought the editor does not show any .vi, but the voltage outputs changed, so the .vi must be running in the background.
The problem is after "vi.Run", the command prompt in MATLAB just freezes, waiting for the .vi to finish. If I close the LabView editor manually, I gain the command prompt back.
I can use
vi.GetControlValue() vi.SetControlValue()
to get and set the slider value, but only before "vi.Run". What I wanted to do is change the slider value during "vi.Run". Is there any way to run "vi.Run" asynchronously?
03-05-2019 11:49 AM
Have your VI with the slider already running, and have the VI you call with VI.run call a different VI, and that one just sends a message of some kind (queue, user event, notifier, updating a FGV, opening the VI reference and finding the control reference from the front panel, etc.) that the other VI already running will get and uses that to trigger the slider to move.
03-06-2019 03:20 PM
Finally figured it out. I just have to launch the LabVIEW executable separately, and hook up to it in MATLAB.
e = actxserver('XXX.Application'); vipath = 'F:\Joe\LabView\test\called_by_matlab.vi'; vi=invoke(e, 'GetVIREference', vipath);Use the above commands in MATLAB to "hook up" to the running LabVIEW executable. "XXX" is the name set during building the executable in LabVIEW, and vipath is .vi that got copied over.
03-07-2019 09:31 AM
If you want to launch an instance of LabVIEW executable via ActiveX from MATLAB, use the following code:
One requirement is LabVIEW has to be installed on the same machine.
e = actxserver('LabVIEW.Application'); vipath = 'F:\Joe\LabView\test\called_by_matlab.vi'; vi=invoke(e, 'GetVIREference', vipath); vi.Run(true);
vi.Run(true) tells the function to run asynchronously.
Here is the document for all the APIs http://zone.ni.com/reference/en-XX/help/371361P-01/axprop/vi_class_method/