Error using StateButton ValueChanged callback in App designer
显示 更早的评论
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
回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!