Reading data from Simulink to GUI using event listener
이전 댓글 표시
Hi,
I have successfully updated the GUI from a simulink with event listener for a simple example. I am basically follow this web How can I update a GUI with values from my Simulink model as it is running?. However, it does not update on GUI when I connected it with my arduino (s-function is used). After that, I checked it on the command window with the following code and the GUI displayed the reading on the Gain block without streaming the data.
>> rto1 = get_param('Sfunction3/Gain','RuntimeObject');
>> str1 = num2str(rto1.OutputPort(1).Data);
>> statestxt1 = findobj('Tag','edit2');
>> set(statestxt1,'string',str1);
I think this is an issue from event listener but I couldn't find any wrong. Please help me if you have any clue.
%StartFcn
%The GUI handles are by default hidden, turn them on
set(0,'ShowHiddenHandles','on');
%Set up the arguments that will go into the gain block event callback listener
blk = 'Sfunc/Multiply';
blk1 = 'Sfunc/Gain1';
blk2 = 'Sfunc/Gain2';
blk3 = 'Sfunc/Gain3';
event = 'PostOutputs';
listener = @updategui;
%Create the listener
h = add_exec_event_listener(blk, event, listener);
h1 = add_exec_event_listener(blk1, event, listener);
h2 = add_exec_event_listener(blk2, event, listener);
h3 = add_exec_event_listener(blk3, event, listener);
function varargout = updategui(varargin)
%create a run time object that can return the value of the gain block's
%output and then put the value in a string.
rto = get_param('Sfunc/Multiply','RuntimeObject');
rto1 = get_param('Sfunc/Gain1','RuntimeObject');
rto2 = get_param('Sfunc/Gain2','RuntimeObject');
rto3 = get_param('Sfunc/Gain3','RuntimeObject');
str = num2str(rto.OutputPort(1).Data);
str1 = num2str(rto1.OutputPort(1).Data);
str2 = num2str(rto2.OutputPort(1).Data);
str3 = num2str(rto3.OutputPort(1).Data);
%get a handle to the GUI's 'current state' window
statestxt = findobj('Tag','edit1');
statestxt1 = findobj('Tag','edit2');
statestxt2 = findobj('Tag','edit3');
statestxt3 = findobj('Tag','edit4');
%update the gui
set(statestxt,'string',str);
set(statestxt1,'string',str1);
set(statestxt2,'string',str2);
set(statestxt3,'string',str3);
댓글 수: 2
Bhavana Sapparapu
2023년 2월 14일
Hi, could you please tell if this issue is still persisting?
gdz
2023년 3월 19일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Event Functions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!