matlab tcpip 回调,matlab tcpip通信

【实例简介】

【实例截图】

731737b9bdd031d2f059ef0dfce8ec72.png

【核心代码】

function udp_plotter_demo(lport)

% UDP_PLOTTER_DEMO - Opens a figure and starts to listen for UDP packages to plot.

% Syntax:

% UDP_PLOTTER_DEMO

% or

% UDP_PLOTTER_DEMO localport

%

% This script is a demo that listen for a UDP packet (default port 3333) and

% uses PLOT to dplay the sequence of doubles in the packet.

%

% (C) 2002 Peter Rydes鋞er

% Add default argument

if nargin<1, lport=3333; end

% Write help message

disp ' ';

disp 'To send packages to be plotted use e.g.';

disp(sprintf(' Use: udp_send_demo sin(0:0.1:6) '));

disp 'or';

disp(sprintf(' Use: udp_send_demo sin(0:0.1:6) HOSTNAME'));

disp ' ';

disp 'To send a package to be plotted';

% Open figure window

fg=figure;

clf; axis; drawnow;

% Open udpsocket and bind udp port adress to it.

udp=pnet('udpsocket',lport);

% Use timeout to not block forever, makes it possible to update resized window.

try,

while 1,

% Wait/Read udp packet to reed buffer

len=pnet(udp,'readpacket');

if len>0,

% if packet larger then 1 byte then read maximum of 1000 doubles in network byte order

data=pnet(udp,'read',1000,'double');

figure(fg);

% .... and plot doubles in axis.

plot(data);

end

drawnow;

end

end

% On break or error close udpconnection and figure window.

pnet(udp,'close');

delete(fg);

return;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值