MATLAB Answers

0

TCP connection with external software

Latest activity Commented on by Walter Roberson
on 17 Jul 2019
Hi to everyone!
I'm experiencing some problems when trying to create a communication between Matlab and OpenSees (a sofware that adopts tcl as programming language) using tcp. In particular I'm able to create the connection adopting this simple script:
clear all;clc
tcpipServer = tcpip('127.0.0.1', 30001,'NetworkRole','server');
fopen(tcpipServer);
X=fread(tcpipServer)
After this command, Matlab stands for the output from the software. Thus, to produce the output, I need to execute the software adopting an external command, and then the output from the software is directly retrieved from matlab.
Now, I need to run the software from the same script instead of using an external command, but if I adopt the following command at the end of the previous script:
system(['OpenSees > source ','Model_joint_pop.tcl'],'-echo');
Matlab does not execute the command until the tcp connection is closed, standing for the output from the connection. Since the software is not executed, Matlab stands for the connection until the timeout is reached. In the same way, if I execute the sofware as a first command, the connection is not found from tcl and the software is aborted.
Is there any solution to execute the software right after the creation of the connection (without executing command as sequential) in order to make Matlab to read the output from the same software?
Thank you in advance.

  3 Comments

Is the communication one way or two way? If it is one way then there is a Process Open contribution in the file exchange.
On ms windows, you can use .net to create two way connections with a process.
Hi thank you for the response.
I need to run the software from Matlab and, then, to retrieve and elaborate the output in Matlab. The problem is that Matlab doesn't run a second command (run the external software) before the first is completely terminated (open tcp). Could you please send me the link to the file exchange page? Thanks
https://blogs.mathworks.com/pick/2017/06/09/launch-and-manage-external-processes-from-matlab/
https://www.mathworks.com/matlabcentral/fileexchange/13851-popen-read-and-write

Sign in to comment.

Tags

0 Answers