matlab之使用TCP/IP协议进行通信

版权声明:如果对您有所启发,欢迎留言告知。若需转载请先联系作者获得许可,转载后请注明出处。 https://blog.csdn.net/yq_forever/article/details/81221599

有时需要数据进行实时处理,使用TCP/IP协议是很好的选择,前提是主机和从机要在同一个网络下。
matlab的tcpip函数做了很好的封装,通过自带的示例我们可以清楚看到该如何使用。

%Start a TCP/IP echo server and create a TCPIP object.
echotcpip('on',4012)
t = tcpip('localhost',4012); %实际换成host的ip地址和端口

%Connect the TCPIP object to the host.
fopen(t)

%Write to the host and read from the host.
fwrite(t,65:74) %注意,这里是ASCII码
A = fread(t, 10);

% Disconnect the TCPIP object from the host and stop the echo server.
fclose(t)
echotcpip('off')

在手机或者其他电脑上安装网络调试助手,可以在matlab端进行调试。

猜你喜欢

转载自blog.csdn.net/yq_forever/article/details/81221599