【发布时间】:2016-05-01 13:13:47
【问题描述】:
存在带有两个按钮的 MATLAB GUI。每个按钮开始执行从 Com-Port(不同)读取串行数据的无限循环。当我按下一个按钮时,while 循环读取串行端口,但是当我按下下一个按钮时,port1 停止,然后 port2 开始读取,当我停止时port2,port1 正在恢复。所以我的问题是,所有带有 while 循环的回调函数如何能够独立并同时工作..
function samplegui_OpeningFcn(hObject, ~, handles, varargin)
handles.output = hObject;
handles.vec_A=[];
handles.vec_B=[];
handles.vec_C=[];
handles.vec_A_1=[];
handles.vec_B_1=[];
handles.vec_C_1=[];
guidata(hObject, handles);
function open_Callback(hObject, eventdata, handles) % push button1 to receive serial data.
cnt=0;
while 1
% Getting data from Serial Port
get_lines=fgets(handles.se) % getting data from serial port
if~isempty(get_lines)
cnt=cnt+1;
if strfind(get_lines,'T') %Parsing data
handles.vec_A=[handles.vec_A;[timet newword]];
plot(handles.vec_A(:,1),handles.vec_A(:,2:end),'r'); % plotting
% Same follows for parsing and plot vec_B and Vec_C
drawnow(); % to update the Plots
end
end
Pause(.05);
end
guidata(hObject, handles);
function open2_Callback(hObject, eventdata, handles) % push button2 to receive serial data.
cnt=0;
while 1
% Getting data from Serial Port
get_lines=fgets(handles.se2) % getting data from serial port2
if~isempty(get_lines)
cnt=cnt+1;
if strfind(get_lines,'T') % Parsing data
handles.vec_A_1=[handles.vec_A;[timet newword]];
plot(handles.vec_A_1(:,1),handles.vec_A_1(:,2:end),'r'); % plotting
% Same follows for parsing and plot vec_B and Vec_C
drawnow(); % to update the Plots
end
end
Pause(.05);
end
guidata(hObject, handles)
【问题讨论】:
标签: multithreading matlab callback matlab-guide