MATLAB App only runs on particular computers
Afficher commentaires plus anciens
This code is not mine and is not commented much, so it's really difficult for me to follow. It runs and works on my University's computers, but when trying to run it on any personal computer, it will not open. If I try to run the app from MATLAB App Designer, the green run button grays out and the stop button cannot be pressed. The App Designer works fine otherwise, which makes me think the app cannot initialize- but only on specific computers for some reason.
This initialization chunk of the code is what I believe is causing the issue:
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
TextArea2 matlab.ui.control.TextArea
Lamp_4 matlab.ui.control.Lamp
Lamp_3 matlab.ui.control.Lamp
Lamp_2 matlab.ui.control.Lamp
Lamp matlab.ui.control.Lamp
ConnecttoArduinoButton matlab.ui.control.Button
StopRecordingButton matlab.ui.control.Button
StartReadingButton matlab.ui.control.Button
SystemDynamicsandVibrationsLab2MotorSpindownLabel matlab.ui.control.Label
FilenameTextArea matlab.ui.control.TextArea
FilenameTextAreaLabel matlab.ui.control.Label
ExportDataButton matlab.ui.control.Button
UIAxes matlab.ui.control.UIAxes
end
properties (Access = private)
Angle % Description
Velocity % Description
Time % Description
sp % serial port object
iCOM
STOPPED
end
% Callbacks that handle component events
methods (Access = private)
function startupFcn(app)
while isempty(app.sp) == true
if (isempty(app.iCOM)==1)
app.iCOM = 0;
end
if (isempty(app.sp)==1)
app.Lamp.Color = [1,0,0];
spl = serialportlist;
% for i = 1:length(spl)
app.iCOM = app.iCOM + 1;
if (app.iCOM > length(spl))
app.iCOM = 1;
end
serialObjectTemp = serialport(spl(app.iCOM), 9600);
configureTerminator(serialObjectTemp,"LF");
writeline(serialObjectTemp,"serialConnectNow")
pause(0.5)
app.TextArea2.Value = spl(app.iCOM);
TtempText = readline(serialObjectTemp);
app.TextArea2.Value = TtempText;
% if serial available and reads "amHere"
if (class(TtempText) == "string")
TtempText = splitlines(TtempText);
if (TtempText(1) == "amHere")
clear serialObjectTemp;
app.sp = serialport(spl(app.iCOM), 9600);
app.ConnecttoArduinoButton.Text = 'Connected';
pause(0.5);
app.Lamp.Color = [0,1,0];
app.ConnecttoArduinoButton.Enable = "off";
end
end
if app.Lamp.Color ~= [1,0,0]
app.ConnecttoArduinoButton.Text = ':(';
end
end
end
end
The app is used to communicate serial data between a computer and an arduino. The initialization app code is meant to find the serialport that the arduino is on, and connect to it so that data can then be exchanged.
I've attempted to run this code on different versions of MATLAB, mainly 2023a, 2023b, 2024a, and 2024b, on university and personal computers. The issue seems independent of MATLAB version and also Windows version (tested on 10 and 11).
Any insight would be helpful, Thank you.
5 commentaires
Do you have the necessary hardware and serial ports on the failing computer(s), first? Most newer machines now use USB ports instead of serial and in cost-cutting every penny, motherboards generally now are devoid of the once ubiquitous buildtin serial port.
Obvious first thing is to try to find/open a serial port from the command line...what does
serialportlist
from the command line return?
Nobody here will really be able to tell anything about the app itself without the complete app code to try to load as far as the ability to use it in AppDesigner
Dylan
le 19 Fév 2025
dpb
le 19 Fév 2025
I downloaded the app and tried to initialize the Arduino -- the red button. Of course, I don't have an Arduino so while it did find the COM port, the return string was empty so it aborted there.
What I notice is there is no error checking in the code, it presumes things are going to work and so if it doesn't, there isn't any evidence if it doesn't crash. Which it did
Warning: The specified amount of data was not returned within the Timeout period for 'readline'.
'serialport' unable to read any data. For more information on possible reasons, see serialport Read Warnings.
Error using matlab.ui.control.TextArea/set.Value (line 109)
'Value' must be a character vector, or a 1-D array of the following type: cell array of character vectors, string, or categorical.
Error in DAVE_MATLAB_Lab3_4_5/startupFcn (line 55)
app.TextArea2.Value = TtempText;
Warning: The specified amount of data was not returned within the Timeout period for 'readline'.
'serialport' unable to read any data. For more information on possible reasons, see serialport Read Warnings.
55 app.TextArea2.Value = TtempText;
This isn't surprising and doesn't solve your problem, but illustrates the app itself does try to run on a totally different system.
Set a breakpoint on line 55 of the StartupFcn and then try with your system and see what is returned, if anything. I'm guessing probably the Arduino is not responding with the expected string of "amHere" and the code then doesn't do anything more; just silently returns without doing anything more, even letting you know it didn't connect...
...
if (TtempText(1) == "amHere")
clear serialObjectTemp;
app.sp = serialport(spl(app.iCOM), 9600);
app.ConnecttoArduinoButton.Text = 'Connected';
pause(0.5);
app.Lamp.Color = [0,1,0];
app.ConnecttoArduinoButton.Enable = "off";
end
...
You'll notice in the above there is no else clause if the test fails so you don't have any indication from the app that something didn't work.
I'm guessing that's where the problem lies; the problem then will be to determine why your machine isn't connecting and another does/can...maybe there's some code that is supposed to be loaded onto the Arduino that causes it to respond with the given string? I've never had an Arduino so no knowledge at all there, sorry.
But, I'm pretty sure the problem is something such as this; the app should have better diagnostics to let the user know when something didn't work as expected.
Dylan
le 19 Fév 2025
Oh. That's different. The main function is down around line 310 or so in the protected code section. It is
function app = DAVE_MATLAB_Lab3_4_5
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
% Execute the startup function
runStartupFcn(app, @startupFcn)
if nargout == 0
clear app
end
end
so, you see it is factored into a very simple top-level code that is easy to trace.
Even though you can't edit the code in App Designer, you can set a breakpoint there and work your way through and see where things go south. Just set the breakpoint on the createComponents line first and F10 to see if it's the component creation that is failing. If that succeeds, then try the next. If it fails to complete, then you can dive into the called functions and see where it actually does hang, presuming that is what is going on.
The code is factored such that starting here will let you isolate where it actually does fail pretty quickly. If it's something in the internal code, you likely will have to have official Mathworks support look into it.
For various reasons, I'm still running R2021b here so I haven't tested more recent releases. App Designer makes a few syntax changes when versions change so the line numbers here may not be identical to yours, but it'll be close enough you can find the main function easily enough.
Réponses (0)
Catégories
En savoir plus sur Develop Apps Using App Designer 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!