Main Content

Broadcast Local Events in Parallel States

Directed Event Broadcast Using Send

This example shows the behavior of directed event broadcast using the send(event_name,state_name) syntax on a transition.

Stateflow chart with top-level parallel states called A and B. A has substates called A1 and A2. B has substates called B1 and B2.

Initially, the chart is asleep. Parallel substates A.A1 and B.B1 are active, which implies that parallel (AND) superstates A and B are also active. The condition [data1==1] is true. The event E_one belongs to the chart and is visible to both A and B.

After waking up, the chart checks for valid transitions at every level of the hierarchy:

  1. The chart root checks to see if there is a valid transition as a result of the event. There is no valid transition.

  2. State A checks for any valid transitions as a result of the event. Because the condition [data1==1] is true, there is a valid transition from state A.A1 to state A.A2.

  3. The action send(E_one,B) executes:

    1. The broadcast of event E_one reaches state B. Because state B is active, that state receives the event broadcast and checks to see if there is a valid transition. There is a valid transition from B.B1 to B.B2.

    2. State B.B1 exit actions (exitB1()) execute and complete.

    3. State B.B1 becomes inactive.

    4. State B.B2 becomes active.

    5. State B.B2 entry actions (entB2()) execute and complete.

  4. State A.A1 exit actions (exitA1()) execute and complete.

  5. State A.A1 becomes inactive.

  6. State A.A2 becomes active.

  7. State A.A2 entry actions (entA2()) execute and complete.

This sequence completes execution of a chart with a directed event broadcast to a parallel state.

Directed Event Broadcast Using Qualified Event Name

This example shows the behavior of directed event broadcast using a qualified event name on a transition.

Stateflow chart with top-level parallel states called A and B. A has substates called A1 and A2. B has substates called B1 and B2.

The only differences from the chart in Directed Event Broadcast Using Send are:

  • The event E_one belongs to state B and is visible only to that state. To assign the event E_one in the scope of state B, in the Model Explorer select the state and add the event.

  • The action send(E_one,B) is now send(B.E_one).

    Using a qualified event name is necessary because E_one is not visible to state A.

After waking up, the chart checks for valid transitions at every level of the hierarchy:

  1. The chart root checks to see if there is a valid transition as a result of the event. There is no valid transition.

  2. State A checks for any valid transitions as a result of the event. Because the condition [data1==1] is true, there is a valid transition from state A.A1 to state A.A2.

  3. The action send(B.E_one) executes and completes:

    1. The broadcast of event E_one reaches state B. Because state B is active, that state receives the event broadcast and checks to see if there is a valid transition. There is a valid transition from B.B1 to B.B2.

    2. State B.B1 exit actions (exitB1()) execute and complete.

    3. State B.B1 becomes inactive.

    4. State B.B2 becomes active.

    5. State B.B2 entry actions (entB2()) execute and complete.

  4. State A.A1 exit actions (exitA1()) execute and complete.

  5. State A.A1 becomes inactive.

  6. State A.A2 becomes active.

  7. State A.A2 entry actions (entA2()) execute and complete.

This sequence completes execution of a chart with a directed event broadcast using a qualified event name to a parallel state.

See Also

Related Topics