Issues with Breaking while loop in Appdesigner.
2 次查看(过去 30 天)
显示 更早的评论
I need to break while loop - which reads a sensor value - I want to break the while loop when pushbutton is pressed.
I tried using "Tag" handle in pushbutton to break the loop - it breaks loops before pushing the pushbutton.
Error:
Error using matlab.ui.control.Button/get
Unrecognized property Value for class Button.
Error in IRgauge/ReadDistanceButtonPushed (line 36)
stop_state = get(app.CLOSEButton,'Value');
Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 382)
Error while evaluating Button PrivateButtonPushedFcn.
Code for reading sensor in appdesigner "Code View"
function ReadDistanceButtonPushed(app, event)
CommPort = serialport('COM30',9600);
while 1
R = readline(CommPort);
R = str2double(R);
app.DISTANCEGauge.Value = R;
drawnow();
stop_state = get(app.CLOSEButton,'Value'); % to break infinity loop
if stop_state
break;
end
end
end
% callback function breaking infinity loop
function CLOSEButtonPushed2(app, event)
close all; clc; delete(instrfind);
end
5 个评论
Franck paulin Ludovig pehn Mayo
2022-1-12
@Ameer Hamza hello , please could you have a look on the link below.
回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Develop Apps Using App Designer 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!