Break doesn't break out of endless loop
1 回表示 (過去 30 日間)
古いコメントを表示
Hey guys!
I am designing an app, where one function is to read out some strings, which are sent from an Arduino.
So basically, the Arduino will send something like
D0.00
D0.05
D0.1
D0.15
DS
over serial. DS is the "stopper" string, so if DS is sent, the app shall stop reading over Serial.
Now, whats frustrating me, is following: My code to read out these strings is
while 1
pause(0.001);
%read out data from serial
received_stringM = fgets(app.s);
%DS is the stopper string, so if it is sent, the while loop should end
if received_stringM == "DS"
break
end
%to display the sent string in an Edit Field
app.currentdistanceEditField_2.Value = received_stringM;
end
This is the Edit Field, where the string is displayed to.

But exactly this is wondering me. The code is very simple, but I thought after the break command, the following lines shouldn't be executed. But obviously, even though DS is sent, it doesn't break, but is displayed.
Does anyone see any mistake in my code?
Thanks for reading and for any advices!
3 件のコメント
Walter Roberson
2019 年 2 月 14 日
for debugging double(received_stringM)
I think you will find that it ends in 13 (carriage return) or 10 (newline) or both.
回答 (1 件)
Walter Roberson
2019 年 2 月 14 日
fgets includes the terminator character . use fgetl instead of fgets
0 件のコメント
参考
カテゴリ
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!