Display continuous stream of serial data in GUI text fields with callback function
Mostrar comentarios más antiguos
My main problem with this code is that the textfields of my GUI don't get updated. I tried using guidata(hObject, handles) at the end of my callback function to update the GUI data but that doesn't seem to work. The handles inside the callback function get updated properly but they are not sent back to the guidata and the text fields don't get updated.
% --- Executes on button press in startCom.
function startCom_Callback(hObject, eventdata, handles)
% hObject handle to startCom (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% This is the callback of the button, which starts the external function.
s = serialport("COM1",9600);
configureTerminator(s,"CR/LF")
writeline(s,"QS")
a=readline(s);
handles = guidata(hObject);
configureCallback(s, "terminator", @(src, evt) displaySerial(src, evt, hObject, handles))
handles = guidata(hObject);
guidata(hObject, handles);
function displaySerial(src, evt, hObject, handles)
handles = guidata(hObject);
data = readline(src);
src.UserData = data;
a = strrep(data,',',' ');
C = string(strsplit(a));
a=str2double(C);
set(handles.fx_output, 'String', a(1,2)/2);
set(handles.fy_output, 'String', a(1,3)/2);
set(handles.fz_output, 'String', a(1,4)/2);
set(handles.mx_output, 'String', a(1,5)/2);
set(handles.my_output, 'String', a(1,6)/2);
set(handles.mz_output, 'String', a(1,7)/2);
set(handles.error_output, 'String', a(1,1)/2);
guidata(hObject, handles);
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Logical 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!