Open an ethernet connection

27 次查看(过去 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 ? :(

类别

Help CenterFile Exchange 中查找有关 Application Deployment 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by