Break a while loop in a GUI Pushbutton
Afficher commentaires plus anciens
Hi there,
I have a GUI set up and it has a Start pushbutton and a Stop pushbutton. Upon pushing the start, data is transmitted and received between AVR and matlab with Serial communication.
What I am trying to do is while the data is communicated and being run, if the stop button is pressed, the while operation should stop. This should be accomplished if I can just break the while loop, but the code that I've tried using 'assignin' and 'evalin' hasn't succeeded. Actually it occasionally works but sometimes doesn't work. Here is what my code :
function StartButton_Callback(hObject, eventdata, handles)
flag = 0;
assignin('base','flag', flag);
bt = Bluetooth('JCNET-BT-7827',1);
fopen(bt);
while 1
%%Receiving and Display Serial Communication
flag = evalin('base', 'flag');
if flag == 1
break;
end
end
When the EndButton is pressed,
% --- Executes on button press in EndButton.
function EndButton_Callback(hObject, eventdata, handles)
flag = 1;
assignin('base','flag', flag);
Could anyone give me for advices? Thanks a lot in advance!
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Interactive Control and Callbacks dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!