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

Geoff Hayes
Geoff Hayes 2017년 12월 4일
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});
Should I note that the callback function "nuskaitymas" is on a separate m file?

댓글을 달려면 로그인하십시오.

답변 (1개)

Greg
Greg 2017년 12월 9일
편집: Greg 2017년 12월 9일

0 개 추천

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

카테고리

도움말 센터File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

질문:

2017년 12월 4일

편집:

2017년 12월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by