Filter löschen
Filter löschen

Adding event listener to simulink model

13 Ansichten (letzte 30 Tage)
Maximilian Schmid
Maximilian Schmid am 12 Jan. 2021
Beantwortet: Adit Alware am 23 Mai 2022
Hi
I'm trying to add an event listener to my model, so the listener is created when I click on run. I can add it during the simulation by typing it in the command prompt. But I need to have it from the beginning of the simulation.
I tried inserting the following command in initFcn and startFcn (tried both),
add_exec_event_listener("v13_2020a/Strategie/Multiply", 'PostOutputs', @myFunction);
but it throws this error:
  • The output of 'add_exec_event_listener' should be assigned to a variable that persists for the duration that the listener is active.
So I'm guessing the problem is, that it adds the listener too early. How can I fix that?

Antworten (1)

Adit Alware
Adit Alware am 23 Mai 2022
Hi Maximilian,
Simulink software can register a listener only while a simulation is running. Invoking the function "myfunction" when no simulation is running results in an error message. To ensure that a listener catches all relevant events triggered by a model's simulation, you should register the listener in the model's StartFcn callback function.
add_exec_event_listener returns a handle to the listener that it registered. So you may try using the command with the following format:
h = add_exec_event_listener(blk,event,listener)
Also, you may refer to the documentation link below:
Thanks

Kategorien

Mehr zu Event Functions finden Sie in Help Center und File Exchange

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by