Open an ethernet connection

조회 수: 30 (최근 30일)
dsq dq
dsq dq 2021년 7월 30일
답변: dsq dq 2021년 8월 17일
Hey everyone ! :)
I am currently trying to open an Ethernet connection with matlab. Because I'm quite new in Matlab programming, my program is not working. Here is what I've done :
echotcpip("on",2049);
t = tcpclient("192.168.10.94", 2049);
message_to_send = "11009¶1¶1";
write(t,message_to_send);
data = read(t,10);
clear t;
echotcpip("off");
I know the message to send is quite strange, but this is the logic of the external device. I'm 100 % sure that the IP adress and the port number are good. I tried to open the connection with Putty and it worked well, but now I'm trying with Matlab it timeout when it's supposed to read the data from the external device. Is my program wrong or I'm stupid and my error is somewhere else ?
Thanks you very much in advance !

답변 (1개)

dsq dq
dsq dq 2021년 8월 17일
Hey everyone,
I'm back from vacation and now I've got this :
IP= '192.168.10.94';
port = 2049;
tcpipObj=tcpip(IP, port);
fopen(tcpipObj);
tcpipObj.Terminator = 'CR/LF';
fprintf(tcpipObj,'11009¶1¶1');
A = fread(tcpipObj,500,'char') ;
A = char (A);
fclose(tcpipObj);
The external device answer, but it takes to much time and I have this warning :
'Warning: The specified amount of data was not returned within the Timeout period.
'tcpip' unable to read all requested data. For more information on possible reasons, see TCPIP Read Warnings. '
I didn't find the solution on Internet and I really know why ... Nobody knows how to fix it ? :(

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by