How to create a multi thread gui
19 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Adrian Bercovici
il 11 Apr 2016
Commentato: Adrian Bercovici
il 12 Apr 2016
Hello how can i plot data real time in a gui?
The code below keeps blocking.I want when i press the close_port_btn the reading to stop. Since i have seen there is no function to get the serial status of the port i created that flag. This flag is intended to stop the reading. Somehow it seems the code won't exit that part of code. Do i need to do multithreading? And if so how can i achieve that?
function read_btn_Callback(hObject, eventdata,handles)
% hObject handle to read_btn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global port;
fopen(port);
handles.flag=1;
N=100;
y=zeros(N,1);
t=linspace(0,N,1);
while (handles.flag~=0)
y(1:end-1)=y(2:end);
x=fscanf(port,'%d')/100
plot(y,'LineWidth',2);
grid on;
axis([0 100 0 50])
end
guidata(hObject,handles);
function close_port_btn_Callback(hObject, eventdata, handles)
% hObject handle to close_port_btn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global port;
fclose(port);
handles.flag=0;
guidata(hObject,handles);
0 Commenti
Risposta accettata
Walter Roberson
il 11 Apr 2016
function read_btn_Callback(hObject, eventdata,handles)
% hObject handle to read_btn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global port;
fopen(port);
handles.flag=1;
guidata(hObject, handles);
N=100;
y=zeros(N,1);
t=linspace(0,N,1);
while true
drawnow();
handles = guidata(hObject);
if handles.flag == 0
break;
end
y(1:end-1)=y(2:end);
x=fscanf(port,'%d')/100
plot(y,'LineWidth',2);
grid on;
axis([0 100 0 50])
end
fclose(port);
function close_port_btn_Callback(hObject, eventdata, handles)
% hObject handle to close_port_btn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.flag=0;
guidata(hObject,handles);
3 Commenti
Walter Roberson
il 11 Apr 2016
You initialize your y to N zeros's and in your loop you shrink y by one element each pass through the loop. An all-zero line could easily be mistaken as not being there.
You read data into x in your loop but you do not store or plot that x.
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!