MATLAB App only runs on particular computers
7 views (last 30 days)
Show older comments
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 Comments
dpb
on 20 Feb 2025
Edited: dpb
on 20 Feb 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.
Answers (0)
See Also
Categories
Find more on Develop Apps Using App Designer in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!