I am setting up a serial communication in matlab without GUI.
The serial initialisation looks like this (main program):
handles.s = serial('COM10' ,'BaudRate', 9600);
set(handles.s,'Terminator','CR');
set(handles.s,'Timeout',1);
set(handles.s, 'BytesAvailableFcnMode', 'byte');
set(handles.s, 'BytesAvailableFcnCount', 1);
set(handles.s, 'BytesAvailableFcn', {@serialEventHandler, handles});
fopen(handles.s);
I am reading the buffer with a callback function (serialEventHandler)
function serialEventHandler(serialConnection, ~, handles)
bytes = get(serialConnection, 'BytesAvailable');
if(bytes > 0 ) % we may have alread read the data
handles.data = fscanf(serialConnection)
% fwrite(handles.appenderFile, handles.data); (not relevant here)
end
end
For some reason, the callback does not update my handles structure and I am unable to access the serial data the main code. I understand this is the role of guidata(hobject, handles) in a GUI application, but is there a way to do this without GUI? Many thanks,