How to use GUI handles in external function?

I have a task, where a server reads incoming messages and works with them to eventually display them on an axis in a GUI. For this task, BytesAvailableFcn is perfect, but I have some problems implementing it. I am able to pass the handles structure to it and to use the variables inside, but I am not able to update it in the end. Parts of my code, that are relevant:
%Configuration of the port
handles.TCPL = tcpip('0.0.0.0', 31010, 'NetworkRole', 'server');
handles.TCPL.BytesAvailableFcnCount = 23;
handles.TCPL.BytesAvailableFcnMode = 'byte';
handles.TCPL.BytesAvailableFcn = {@nuskaitymas,handles};
%
%
%
%
%The callback function-----------------------------------------------------------
function nuskaitymas(hObject,eventdata,handles)
%Takes the handles structure, uses variables inside it
.
.
.
%This part of the code is not relevant
.
.
.
%Update handles structure
guidata(hObject, handles);
end
----------------------------------------------------------------------------------
What happens is when I call "guidata", the hObject gets marked with an error. Any ideas?
Also, what I have tried is instead of doing the calculations inside the callback, is to change a global variable inside the callback to stop a while loop inside the main function of the GUI, but what happens is that the program waits for the while loop to stop, before calling the BytesAvailableFcn.

3 comentarios

Geoff Hayes
Geoff Hayes el 4 de Dic. de 2017
Tautvydas - you say that What happens is when I call "guidata", the hObject gets marked with an error. What is the error? Please copy and paste the full error message to your question.
This is the error that I get
Error using guidata (line 87)
H must be the handle to a figure or figure descendent.
Error in nuskaitymas (line 80)
guidata(hObject, handles);
Error in instrcb (line 36)
feval(val{1}, obj, eventStruct, val{2:end});
Tautvydas Belgeras
Tautvydas Belgeras el 7 de Dic. de 2017
Should I note that the callback function "nuskaitymas" is on a separate m file?

Iniciar sesión para comentar.

Respuestas (1)

Greg
Greg el 9 de Dic. de 2017
Editada: Greg el 9 de Dic. de 2017
function nuskaitymas(hObject,eventdata,handles)
Is the callback for your tcpip object. The hObject argument is therefore the tcpip object itself (not a graphics component of your GUI) which is not compatible with guidata.
Change the last line to:
guidata(handles.figMyGUI,handles); % Change "figMyGUI" to any valid graphics object tag in handles

Preguntada:

el 4 de Dic. de 2017

Editada:

el 9 de Dic. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by