Matlab App Designer does not respond after running for ~15min

1 回表示 (過去 30 日間)
Anna Lübbers
Anna Lübbers 2022 年 1 月 16 日
コメント済み: Anna Lübbers 2022 年 1 月 25 日
Hello,
I am relatively new to Matlab and I'm trying to use several sensors to measure temperature, pressure etc.
Therefor I use the Arduino Mega2560. In the Arduino IDE I read out the measured values. In Matlab App Designer I use the Serial-API to get the values.
In the app the measured values are displayed in diagrams and can be saved after pressing a button.
After running the code for about 15-20 minutes the program doesn't respond any more, e.g. pressing a button does not cause any action any more. Additional I am not able to close the window at all.
I need to execute those actions, because the measurement has to run for about 20 minutes and than I have to stop the code, so that the values get stored in a file.
Thanks! I hope someone can help me :)
Here is my code: (for only one sensor for easier understanding)
function startupFcn(app)
% Arrays for saving values
vals1 = [];
saveButton = 0;
% Initalizing Diagrams
app.UIAxesTemp.XLim = [0 100];
app.UIAxesTemp.YLim = [0 70];
% variable to check if any values are in the arrays already
valuesInArray = 0;
% variable to see if values should be saved already
savevalues = 0;
% variable to see if a file alrady have been saved
filesaved = 0;
% variable to claim which sensor should be read
neededSensor = 0;
% variables for getting time
t1 = now;
t11 = datevec(t1);
% Initializing Serial-API
delete(instrfind({'port'},{'COM7'}));
s=serial('COM7', 'BaudRate', 9600, 'Terminator','CR');
fopen(s);
while app.StopProgram.Value == 0
%Read data
data = fscanf(s);
temp = string(data);
t2 = now;
t22 = datevec(t2);
time = etime(t22,t11);
if regexp(temp, "[0-5] {1,}[0-9]{1,}.[0-9]{1,}") %format of output of Arduino IDE
% sensorNr: the number of the sensor, from which the
% value is coming
sensorNr = cast(extractBetween(temp, 2, 2), 'double');
value = cast(regexp(temp, '([0-9]{1,}.[0-9]{1,})', 'match'), 'double');
switch neededSensor
case 1
app.Sensor2TemperaturinCEditField.Value = value;
hold(app.UIAxesTemp, 'on');
s2 = plot(app.UIAxesTemp,time,wert,'xm');
if saveButton == 1
vals1 = [vals1; value];
valuesInArray = 1;
end
% case 2,3,4 etc. (for more sensors)
saveButton = app.SpeichernButton.Value;
end
%needed sensor count up (doesnt matter for this problem)
else
disp("No data found.");
end
fileName = app.FileNameEditField.Value;
%Look if there are values in the Arrays, if the saveButton
%is deactivated again and if the file hasn't been saved yet.
if valuesInArray == 1 && saveButton == 0 && fileSaved == 0;
finalData = [vals1]; %other arrays for more sensors
writematrix(fin, strcat('C:\Users\[...]',fileName,'.xlsx'));
fileSaved = 1;
end
pause(0.1);
end
close(app.UIFigure);
end

回答 (1 件)

Michael Van de Graaff
Michael Van de Graaff 2022 年 1 月 17 日
You have an fopen but no fclose. that's generally not a great idea in my experience
Is fopen even supposed to be used in this context?
  3 件のコメント
Anna Lübbers
Anna Lübbers 2022 年 1 月 24 日
I think using serialport solved the problem. So I didn't have to use fopen anymore either.
Anna Lübbers
Anna Lübbers 2022 年 1 月 25 日
Hello, unfortunately, serialport did not solve the problem. Yesterday I had suspected this because the program ran fine for 30 minutes. Today, however, the program has again stopped responding after about 15-20 minutes. It did output the measured data. But the values could not be saved, a diagram, whose borders should change over time, did not expand anymore and the buttons did not react to a click. Do you have any other ideas why this problem occurs?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGaussian Process Regression についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by