Clear Filters
Clear Filters

Error using StateButton ValueChanged callback in App designer

10 views (last 30 days)
Hi, I'm developping an app for controlling instruments. One of my state button was working well until yesterday. I didn't change it's code, technically the changed I've made should not affect it's callback function. here is the error I get:
matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 352)
Error while evaluating StateButton PrivateValueChangedFcn.
Here is my callback function:
function XPSConnectButtonValueChanged(app, event)
value = app.XPSConnectButton.Value;
IP = app.XpsIPAdressEditField.Value;
Port = app.XpsPortEditField.Value;
timeout = app.XpsTimeOutEditField.Value;
if value==true
app.SocketID = TCP_ConnectToServer(IP,Port,timeout);
if app.SocketID==-1 % failed
message = ['Connection to XPS Server Failed: check if the drivers have been loaded,',...
'check the connection cables or increase the time out'];
uialert(app.UIFigure, message, 'Error', 'Icon', 'error');
app.XPSConnectButton.Value = false;
elseif app.SocketID==1e6 % ID didn't change ==> no response from driver
message = 'Connection to XPS Server Failed: check if the drivers have been loaded';
uialert(app.UIFigure, message, 'Error', 'Icon', 'error');
app.XPSConnectButton.Value = false;
else % Success
% Connection is ok, let's enable movements on the driver
% Long coding using instruments drivers
% Ready
message = 'XPS Server connected succesfully';
uialert(app.UIFigure, message, 'Success','Icon', 'success');
app.XPSConnectButton.BackgroundColor = 'g';
app.XPSConnectButton.Text = 'CONNECTED';
% Start the timer for reading the values
start(app.StageUpdateTimer);
end
else % changed from true to false ==> disconnect then
TCP_CloseSocket(app.SocketID);
uialert(app.UIFigure, ' Disconnected successfully', 'Success','Icon', 'success');
app.XPSConnectButton.BackgroundColor = 'r';
app.XPSConnectButton.Text = 'NOT CONNECTED';
% app.XPSConnectButton.Value = false;
stop(app.StageUpdateTimer); % Stop the timer which updates the position values
end
end
  1 Comment
Dam-Be Douti
Dam-Be Douti on 13 Jul 2018
Solved ! Just that for some errors inside the callback function of button, matlab seems to not know how to report them and then report StateButton Evaluation error. The error has nothing to do with the StateButton actually, but with my instrument connections return.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!