Error while evaluating UIControl Callback.
Mostrar comentarios más antiguos
I am trying to add the functionality to an oppen source code. I made a new function and called it in the existing code. However, following error is generating on execution of the code. Although the code and new function added is working fine standalone. Please help how to overcome this isue.
"Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)gui_rx('rx_b_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback."
Following is the code.
function rx_b_Callback(hObject, eventdata, handles)
set(handles.editor,'String','')
set(handles.rx_b,'Enable','off'); pause(0.1)
handles.acc=[ ];
set(handles.stop_b,'UserData',0)
while 1
if get(handles.stop_b,'UserData') % Verificar ID de parada
break
end
if handles.SerPIC.BytesAvailable
A=fscanf(handles.SerPIC); % Leer buffer de entrada
%%%%%%%%%%%%%%%%%%%%%% Error Generating Code %%%%%%%%%%%%%%%%%%%%%%%%%%
seperate_sensor_data_and_convertvalues(A);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
set(handles.editor,'String',handles.acc)% Escribir mensaje
end
pause(0.02);
end
% --- FUNCIÓN DE PARADA DEL CICLO DE ADQUISICIÓN.
function stop_b_Callback(hObject, eventdata, handles)
% Colocar el ID en 1 para romper el ciclo while
set(handles.stop_b,'UserData',1)
% Cerrar el puerto serial
if strcmp(handles.SerPIC.Status,'open')
fclose(handles.SerPIC);
end
% Habilitar botones
set(handles.rx_b,'Enable','off')
set(handles.com_ser,'Enable','on')
% Borrar edit-text
set(handles.editor,'String','')
% Mensaje de aviso de cierre del puerto
warndlg('Reception END','WARNING RS-232')
% Actualizar estructura handles
guidata(hObject,handles)
%%%%%%%%%%%%%%%%%Function to calculate critical values of co2, co, and Temp
function seperate_sensor_data_and_convertvalues(packet)
packet=erase(packet," "); %str = erase(str," ") erease character from string
sensor_id= extractBefore(packet,"!");
packet = extractafter(packet,"!");
co2= hex2dec(extractBefore(packet,"!"));
if (check_critical_co2(co2))
msgbox("Co2 Critical")
end
packet = extractafter(packet,"!");
temp= hex2dec(extractBefore(packet,"!"));
packet = extractafter(packet,"!");
co= hex2dec(extractBefore(packet,"!"));
function output = check_critical_co2(val)
co2ppm=((val/4096)*2.5)*1000-200;
if (co2ppm >= 2000 ) && (co2ppm <= 5000)
output=true;
else
output=false;
end
3 comentarios
Guillaume
el 24 de Feb. de 2020
All we can tell from the error message is that there's something wrong going on in your rx_b_Callback. Most likely, it's a bug or some situation that occurs tha you haven't thought of.
Most likely culprits:
- One of the fields of handles doesn't exist when the callback is called. Make sure that all the fields (rx_b, stop_b, serpic, editor) are created in the OpeningFcn callback.
- If for some reason the port SerPIC is not open (or has closed unexpectedly) when the callback is called, it will error.
- Your seperate_sensor_data_and_convertvalues assumes that the message received conforms to a particular format. You never check that it actually does and if it doesn't (e.g somehow the message is corrupted), the function may error.
To know for sure, at the command prompt issue:
dbstop if caught error
then run your GUI. When it errors inside the callback, matlab will break into the debugger. See where it stops and what the new error message is and report back. For more information about debugging, see the documentation and to go back to the normal state of behaviour after you're done debugging:
dbclear if caught error
Kamran Latif
el 25 de Feb. de 2020
Walter Roberson
el 26 de Feb. de 2020
We need the complete error message.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Programming en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
