An event is a Stateflow® object that can trigger actions in one of these objects:
A parallel state in a Stateflow chart.
Another Stateflow chart.
A Simulink® triggered or function-call subsystem.
For simulation purposes, there is no limit to the number of events in a Stateflow chart. However, for code generation, the underlying C compiler enforces a theoretical limit of 231-1 events.
An implicit event is a built-in event that is broadcast during chart execution. These events are implicit because you do not define or trigger them explicitly. For more information, see Define Chart Behavior by Using Implicit Events.
An explicit event is an event that you define explicitly. Explicit events can have one of these scopes.
|Input||Event that is broadcast to a Stateflow chart from outside the chart. For more information, see Activate a Stateflow Chart by Sending Input Events and Design Human-Machine Interface Logic by Using Stateflow Charts.|
|Local||Event that can occur anywhere in a Stateflow chart but is visible only in the parent object and its descendants. Local events are supported only in Stateflow charts in Simulink models. For more information, see Broadcast Local Events to Synchronize Parallel States.|
|Output||Event that occurs in a Stateflow chart but is broadcast to a Simulink block. Output events are supported only in Stateflow charts in Simulink models. For more information, see Activate a Simulink Block by Sending Output Events.|
You can define explicit events at these levels of the Stateflow hierarchy.
|Level of Hierarchy||Visibility|
|Chart||Event is visible to the chart and all its states and substates.|
|Subchart||Event is visible to the subchart and all its states and substates.|
|State||Event is visible to the state and all its substates.|
You can add events to a Stateflow chart by using the Symbols pane, the Stateflow Editor menu, or the Model Explorer.
In the Modeling tab, under Design Data, select Symbols Pane.
Click the Create Event icon .
In the row for the new event, under TYPE, click the icon and choose:
Edit the name of the event.
For input and output events, click the PORT field and choose a port number.
To specify properties for the event, open the Property Inspector. In the Symbols pane, right-click the row for the event and select Explore. For more information, see Set Properties for an Event.
In a Stateflow chart in a Simulink model, select the menu option corresponding to the scope of the event that you want to add.
|In the Modeling tab, under Design Data, click Event Input.|
|In the Modeling tab, under Design Data, click Event Output.|
|In the Modeling tab, under Design Data, click Local Event.|
In the Event dialog box, specify data properties. For more information, see Set Properties for an Event.
In the Modeling tab, under Design Data, select Model Explorer.
In the Model Hierarchy pane, select the object in the Stateflow hierarchy where you want to make the new event visible. The object that you select becomes the parent of the new event.
In the Model Explorer menu, select Add > Event. The new event with a default definition appears in the Contents pane of the Model Explorer.
In the Event pane, specify the properties of the event. For more information, see Set Properties for an Event.
You can display the properties of an input or local event, or open the destination of an output event directly from a Stateflow chart. Right-click the state or transition that contains the event of interest and select Explore. A context menu lists the names and scopes of all resolved symbols in the state or transition. Selecting an input or local event from the context menu displays its properties in the Model Explorer. Selecting an output event from the context menu opens the Simulink subsystem or Stateflow chart associated with the event.
sendCommand to Broadcast Explicit Events in Actions
To broadcast explicit events in state or transition actions, use the
send command. Using this command enhances readability of
a chart and ensures that explicit events are not mistaken for data. For more
information, see Broadcast Local Events to Synchronize Parallel States.
Use conditions on transitions instead of events when you want to:
Represent conditional statements, for example,
[x == 0].
Represent a change of data value, for example,
For more information, see Transition Action Types.
enterto Check State Activity
To check state activity, use the
in operator instead of the
enter. For more information, see Check State Activity by Using the in Operator.
Mixing input events that use edge triggers and function calls results in an error during parsing and simulation.