adding second listener to programm with 1 listener
11 ビュー (過去 30 日間)
古いコメントを表示
Hi, could you help me.. I wantto add a second listener(first one Switch1 Output, second Switch2 Output) to function like this: http://techsource-asia.com/edm/2011Aug/tips1.html
This is function for 1 listener:
function SampleFunction
ModelName = 'zbuferem';
% Opens the Simulink model
open_system(ModelName);
% Simulink may optimise your model by integrating all your blocks. To
% prevent this, you need to disable the Block Reduction in the Optimisation
% settings.
set_param(ModelName,'BlockReduction','off');
% When the model starts, call the localAddEventListener function
set_param(ModelName,'StartFcn','localAddEventListener');
% Start the model
set_param(ModelName, 'SimulationCommand', 'start');
% Create a line handle
global ph;
ph = line([0],[0]);
end
% When simulation starts, Simulink will call this function in order to
% register the event listener to the block 'SineWave'. The function
% localEventListener will execute everytime after the block 'SineWave' has
% returned its output.
function eventhandle = localAddEventListener
eventhandle = add_exec_event_listener('zbuferem/Switch1', ...
'PostOutputs', @localEventListener);
end
% The function to be called when event is registered.
function localEventListener(block, eventdata)
disp('Event has occured!')
global ph;
%nn1 = block.NumOutputPorts %you've set this to 1
% Gets the time and output value
gather=[];
simTime = block.CurrentTime
simData = block.OutputPort(1).Data
%simData2 = block.OutputPort(2).Data;
% Gets handles to the point coordinates
xData = get(ph,'XData');
yData = get(ph,'YData');
gather = yData
n = 2000;
xData = [xData simTime];
yData = [yData simData(1)];
% Update point coordinates
set(ph,...
'XData',xData,...
'YData',yData);
% The axes limits need to change as you scroll
samplingtime = .01;
%Sampling time of block 'SineWave'
offset = samplingtime*n;
xLim = [max(0,simTime-offset) max(offset,simTime)];
set(gca,'Xlim',xLim);
drawnow;
end
I want to listen to Switch1 Output and Switch2 Output and then I'd like to have one chart for each signal. I tried it in many ways but it still doesnt work.
so I tried to add the second listener
eventhandle{1}= add_exec_event_listener('zbuferem/Switch1', ...
'PostOutputs', @localEventListener);
eventhandle{2} = add_exec_event_listener('zbuferem/Switch2', ...
'PostOutputs', @localEventListener);
and then to make global ph2, but how can I determine this: now listen to eventhandle1 and update the lines, stop this and listen to eventhandle2...
I tried to add
disp('Event has occured!')
viewing(1).blockHandle = get_param('zbuferem/Switch1','Handle');
ph=lineHandles(viewing{1}.blockHandle)
before
global ph;
and also to delete eventlistener1 after..
but I did smth wrong or do you have any idea
thank you, greetings
0 件のコメント
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Event Functions についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!