Using multiple Event Listener

16 vues (au cours des 30 derniers jours)
Franzi
Franzi le 26 Oct 2011
Hello,
I've created a Simulink file which contains ~5 blocks with permanently changing data. Now, I'd like to create an event listener for each block.
I've generated the following code for each block's startfcn:
%The GUI handles are by default hidden, turn them on
set(0,'ShowHiddenHandles','on');
%Set up the arguments that will go into the block event callback listener
blk_SpO2 = 'Parameter_Final/SpO2';
event = 'PostOutputs';
listener = @Gruppeneinteilung;
%Create the listener
h = add_exec_event_listener(blk_SpO2, event, listener);
and
%The GUI handles are by default hidden, turn them on
set(0,'ShowHiddenHandles','on');
%Set up the arguments that will go into the block event callback listener
blk_BD = 'Parameter_Final/BD';
event = 'PostOutputs';
listener = @Gruppeneinteilung;
%Create the listener
h = add_exec_event_listener(blk_BD, event, listener);
...
My problem is, Simulink only creates a listener for one of the 5 blocks. If I delete that block another one will have a listener and so on. But I'm not able to execute all these listeners at the same time.
Is there anyone who can help me?
greetings, franzi

Réponse acceptée

Daniel Shub
Daniel Shub le 26 Oct 2011
I think the listeners you create with add_exec_event_listener are similar to the listeners you create with addlistener in MATLAB. I think you want the equvilent of the listeners you get with event.listener in MATLAB. The difference being that the listener h that you are creating gets deleted when you overwrite h, but adding your second listener. I think you need to make h an array
h(1) = add_exec_event_listener(blk_SpO2, event, listener);
h(2) = add_exec_event_listener(blk_BD, event, listener);

Plus de réponses (3)

Franzi
Franzi le 27 Oct 2011
Hi!
thanks for the fast answer!
Unfortunately, it doesn't work.
I get the following error message (with or without using arrays):
"Warning: Error occurred while evaluating listener callback. ??? Undefined function or method 'Gruppeneinteilung' for input arguments of type 'Simulink.RunTimeBlock'."
Gruppeneinteilung is my Matlab-File in which I process the block's data.
  1 commentaire
Franzi
Franzi le 27 Oct 2011
it seems the error message doesn't have anything to do with my problem. It also appears when everything's working correctly (using just one block).

Connectez-vous pour commenter.


Franzi
Franzi le 27 Oct 2011
tried it again and IT WORKS! :D
there is still only one listener visible in Simulink (antenna symbol) but my GUIDE- / Matlab- File works perfectly!
Thank you so much!
greetings,
franzi

Gheorghe Schreiber
Gheorghe Schreiber le 4 Nov 2021
Hello,
I have a problem which may be related to OP question, but may be slightly different as in the converse of OP.
I have one simulink model with one block containing ~48 changing signals, divided in 4 groups of 12.
I want to have 4 instances of MATLAB apps running simultaneously, each app monitoring 12 signals at a time.
Is this possible to have multiple listeners in one simulink model sending data to multiple MATLAB apps?
Thank you,
-Gheorghe S

Catégories

En savoir plus sur Event Functions dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by