📄 connecttosocket.m
字号:
function moteIF = connectToSocket(socket)
%CONNECTTOSOCKET
%
% usage: moteIF = connectToSocket('localhost:9000')
%
%This function takes a string and connects to that socket.
%
%If the connection already exists, it returns the moteIF object that did
%it.
%
%IF the connection cannot be made, an error is given.
global COMM
c=find(socket==':');
if ~ischar(socket) | isempty(c) | c==1 | c==length(socket)
warning(' usage: connectToSocket(''localhost:9000'')');
end
TF=strcmp(COMM.sockets, socket);
if any(TF)
moteIF=COMM.moteIF{TF};
return
end
try
host=socket(1:c-1);
port=str2num(socket(c+1:end));
moteIF = net.tinyos.message.MoteIF(host, port, COMM.groupID, COMM.packetLength, 0);
moteIF.start;
COMM.sockets{end+1}=socket;
COMM.moteIF{end+1}=moteIF;
catch
moteIF=[];
warning(['Could not connect: ' socket])
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -