How to use GUI handles in external function?
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Greg
2017-12-9
编辑:Greg
2017-12-9
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
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!