LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Labview controlling Matlab

I'm trying to get Labview 8.6 to programatically launch and run MATLAB 7.5.0.  We have routines currently written in MATLAB that interface with a third party's software to download data from some proprietary equipment.  Is there an ActiveX example or a better way to get Labview and MATLAB to talk nicely?  I've written a bare bones vi that will allow me to launch MATLAB but I keep getting an "Unexpected MATLAB operator" error when I try to use the Execute method on the MLAPP.DIMLApp Invoke Node.  I'm not even sure if this is the right approach for what I'm trying to do.

 

I've searched the forums for hours and have found a couple of clues but most of the comments are to use MathScript or MATLAB Scripts and I don't think these will allow me to retain the comm functionality with the other software.  

 

Ultimately, it would be nice if I could remotely launch MATLAB and run selected .m files.  I would also need to pass small amounts of data back and forth from the Labview GUI to the MATLAB back end.  Any help would be greatly appreciated!

 

Larry 

0 Kudos
Message 1 of 7
(4,447 Views)

Hello Larry

 

It seems what you want to do is already implemented in the "Matlab Script Node". This structure allows you to communicate LabVIEW and Matlab (using ActiveX under the hood). Once your LabVIEW program reaches the script node, it will launch Matlab automatically (no need to launch it yourself and , of course, Matlab has to be installed) and Matlab will execute the commands written in the script. The results will then be send to LabVIEW.

 

I Hope this helps

Javier Gutierrez

Product Marketing

0 Kudos
Message 2 of 7
(4,435 Views)

Javier,

 

I did get the MATLAB Script Node to work with loading a .m file by modifying the Lorenz Diff Eq example.  The problem I'm afraid I'll have is when I try doing this remotely.  The test setup will have one machine with Labview installed that controls the positioning of the device under test and another machine with MATLAB installed that downloads and manipulates the data from various pieces of equipment.  I'm not able to install Labview on the Matlab machine, it performs other functions so it has to be left as is.

 

The way the test used to be run manually was a tech sat at the MATLAB machine in the other room, started the test with MATLAB, took one measurement then walked into the test chamber and realigned the fixture then repeated the process.  In order to somewhat automate this process, one of the engineers here used a macro program that would run off the Labview machine to step through the MATLAB software just as an operator would.  I'm not that familiar with the setup yet but I know there's got to be a more elegant solution.  Some way of Labview and MATLAB to be able to handshake across the network.  I'd like to leave the MATLAB code alone as much as possible, I'm not that familiar with the product and the engineer that wrote it has minimal time to support any changes.  Any thoughts?

 

Thanks,

 

Larry 

0 Kudos
Message 3 of 7
(4,413 Views)

Have you thought about using a program such as TightVNC to remotely log into the other machine?  I'm sure you have, but if the need is short term this might be easier than anything else.

 

You might be able to do it by writing and compiling an executable in LabVIEW that would run on the MATLAB machine but could communicate with the other machine.  I'm pretty sure it can be done this way.  The program on the MATLAB machine would have to 

  1.  Communicate via TCP/IP with the LabVIEW machine to receive messages.
  2.  Process the received messages to select the appropriate m file and run it. 
If you have the Full Development version, I believe you can compile programs into exe files.
Message Edited by rpursley8 on 07-07-2009 05:18 PM
Randall Pursley
0 Kudos
Message 4 of 7
(4,395 Views)

Randall,

 

I did think about the VNC route but it's still somewhat of a cumbersome solution.  If I can work this out, there's a good chance that it will be implemented on other similar setups so I'd like to keep it as robust as possible.  

 

I may look into doing what you suggested about setting up a seperate prog on the MATLAB machine to do the comm but that still won't let me do any user input into MATLAB.  What it comes down to is I'll either have to modify the MATLAB program so that I can have the Labview machine run individual .m files like you suggested or modify the MATLAB code so that instead of looking for a user to type something in the command window, it will look for some data in a text file that I will update via Labview.

 

Thanks,

 

Larry 

0 Kudos
Message 5 of 7
(4,386 Views)

I agree, the VNC route is overkill.  What I think you should do is write a standalone LabVIEW application that reads an INI file and executes the desired M-files.  To control the program remotely over a network, simply incorporate a Remote Front Panel and webservices into theLabVIEW VI. Just go toTools --> Web Publishing Tool to add this functionality to your VI.  Also make sure that the appropriate settings are enabled in the Web Services section of Tools --> Option.  The LabVIEW help should have all the information you need to get going.

 

Then what you will have is a LabVIEW executable (only LabVIEW runtime engine needs to be installed on that machine, and MatLAB of course) running on the remote machine that you can control through your web-browser on the machine you are sitting at.  Follow the links below for some more information.

 

Developing Remote Front Panel LabVIEW Applications

 

Web Publishing Tool Dialog Box

 

 

Chris Bakker
SET Americas
CEO

0 Kudos
Message 6 of 7
(4,365 Views)

Thanks Bakk, I think this is the best solution.  I need to consult with the MATLAB programmer first though to see how difficult it would be to take the existing code and break it up into segments that Labview can run.  I also need to verify that there will be support for all the functions that currently are being used. 

 

Since I'm relatively inexperienced in MATLAB, I may still try to use a status file that both MATLAB and Labview can access.  This file will tell MATLAB when Labview has completed it's tasks and also will have the parameters that the user would normally type into the MATLAB command window.  That would allow the MATLAB program to remain relatively the same, it would just need a routine to check the file instead of asking for user input.

 

Larry

0 Kudos
Message 7 of 7
(4,358 Views)