Stateflow | ![]() ![]() |
Transitioning from State to State with Events Example
The following example shows the behavior of a simple transition focusing on the implications of whether states are active or inactive.
Processing of a First Event
Initially the Stateflow diagram is asleep. State On
and state Off
are OR states. State On
is active. Event E_one
occurs and awakens the Stateflow diagram. Event E_one
is processed from the root of the Stateflow diagram down through the hierarchy of the Stateflow diagram:
E_one
. A valid transition from state On
to state Off
is detected.
On
exit actions (ExitOn()
) execute and complete.
On
is marked inactive.
E_one
is broadcast as the transition action.
E_one
is processed, but because neither state is active, it has no effect. Had a valid transition been possible as a result of the broadcast of E_one
, the processing of the first broadcast of E_one
would be preempted by the second broadcast of E_one
. See Early Return Logic for Event Broadcasts.
Off
is marked active.
Off
entry actions (entOff()
) execute and complete.
This sequence completes the execution of the Stateflow diagram associated with event E_one
when state On
is initially active.
Processing of a Second Event
Using the same example, what happens when the next event, E_one
, occurs while state Off
is active?
Again, initially the Stateflow diagram is asleep. State Off
is active. Event E_one
occurs and awakens the Stateflow diagram. Event E_one
is processed from the root of the Stateflow diagram down through the hierarchy of the Stateflow diagram with the following steps:
Off
exit actions (exitOff()
) execute and complete.
Off
is marked inactive.
On
is marked active.
On
entry actions (entOn()
) execute and complete.
This sequence completes the execution of the Stateflow diagram associated with the second event E_one
when state Off
is initially active.
Processing of a Third Event
Using the same example, what happens when a third event, E_two
, occurs?
Notice that the event E_two is not used explicitly in this example. However, its occurrence (or the occurrence of any event) does result in behavior. Initially, the Stateflow diagram is asleep and state On
is active.
E_two
is processed from the root of the Stateflow diagram down through the hierarchy of the Stateflow diagram:
E_two
. There is none.
On
during actions (durOn()
) execute and complete.
This sequence completes the execution of the Stateflow diagram associated with event E_two
when state On
is initially active.
![]() | Label Format for a State-to-State Transition Example | Transitioning from a Substate to a Substate with Events Example | ![]() |