2つのプッシュボタン付きMATLAB GUIがあります。各プッシュボタンは、Com-Port(異なる)からシリアルデータを読み取る無限ループの実行を開始します。その後、ポート1停止し、ポート2開始読んで、私はポート2を停止したときに、ポート1が再開、私は、whileループはシリアルポートを読んでプッシュボタンを押すと、私は次のプッシュボタンを押すと、 。だからここに私の質問は、時間でつのタスクを実行することしかできないので、あなたは、MATLABでこれを行うことはできませんどのようにすべてのコールバック関数ループが独立して同時に作業することができますしながら、と..コールバック関数を独立して実行する方法matlab
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)
予想されるデータ量が重要な場合はタイマーを使用する傾向がありますが、シリアルポート 'byteavailableFcn'のビルトインコールバックについても言及しています。また、シリアルポートにデータが到着したときに静かに鳴り、 。 – Hoki
@Sueverポートからのデータをそれぞれ保存してプロットすることは可能ですか? – MaK
@MaKシリアルポートごとに別々のコールバックを設定し、コールバック内でカスタムプロットを行うことができます。 – Suever