当然,除了 BytesAvailableFcn 之外,matlab还有datagramreceivedfcn在新的dagatrams上调用你的自定义函数,这是非阻塞而fread / fscanf阻塞(暂时) .
关于matlab中的回调,请阅读events and cbs
Compillable standalone可能如下所示:
%% standalone main
%{
see docs/*
%}
function exitcode = main(port, remotePort)
% sanitize input
if(~exist('port','var') || ~exist('remotePort','var'))
disp(['args: port remotePort']);
exit(1);
end
if ischar(port)
port=str2num(port);
end
if ischar(remotePort)
remotePort=str2num(remotePort);
end
% create udp object
u = udp('127.0.0.1',remotePort, 'LocalPort', port);
% connect the UDP object to the host
fopen(u);
exitcode = 0;
% since we poll, suppress warning</