Main Content

Broadcast Local Events to Synchronize Parallel States

A local event is an event that occurs in a Stateflow® chart and is visible only in the chart. This type of event enables parallel (AND) states in the same chart to synchronize with one another, so that actions in one state trigger actions in the other state. An action in one chart cannot broadcast local events to states in another chart. To define a local event:

  1. Add an event to the Stateflow chart, as described in Define Events in a Chart.

  2. Set the Scope property for the event to Local.

Local events are not supported in standalone Stateflow charts in MATLAB®. For more information, see Synchronize Model Components by Broadcasting Events.

Broadcast Local Events

A directed event broadcast sends a local event directly from one state to another by using the operator send:

send(event_name,state_name)
event_name is a local event and state_name is a receiving state. The local event is broadcast directly to the receiving state and any of its substates. The local event must be visible to both the sending state and the receiving state. The receiving state must be active during the event broadcast.

For example, this chart contains two parallel (AND) states, A and B. The local event E_one belongs to the chart and is visible to both states. In state A, the transition from substate A1 to substate A2 uses a directed event broadcast of the form send(E_one,B) to send the local event E_one to state B. In B, the event triggers the transition from substate B1 to substate B2. Therefore, the active substates in A and B are synchronized. For more information on the semantics of this example, see Directed Event Broadcast Using Send.

Stateflow chart that uses a directed event broadcast to synchronize the substates of two parallel (AND) states.

The state_name argument can include a full hierarchy path to the state. For example, if the state A contains the state A1, you can send an event E to state A1 with this broadcast:

send(E,A.A1)

Tip

Do not include the chart name in the full hierarchy path to a state.

Use Qualified Event Names in Event Broadcasts

To broadcast a local event that is not visible to the sending state, use the operator send with a qualified event name:

send(state_name.event_name)
event_name is a local event that is owned by the receiving state state_name. The local event is broadcast directly to the receiving state and any of its substates. The local event is visible to the receiving state, but not to the sending state. The receiving state must be active during the event broadcast.

For example, this chart contains two parallel (AND) states, A and B. The local event E_one belongs to state B and is visible only to that state. In state A, the transition from substate A1 to substate A2 uses a directed event broadcast of the form send(B.E_one) to send the local event E_one to state B. In B, the event triggers the transition from substate B1 to substate B2. Therefore, the active substates in A and B are synchronized. For more information on the semantics of this example, see Directed Event Broadcast Using Qualified Event Name.

Stateflow chart that uses a directed event broadcast to synchronize the substates of two parallel (AND) states. The broadcast uses the qualified event name B.E_one.

The state_name argument can include a full hierarchy path to the receiving state. Do not use the chart name in the full path name of the state. For example, suppose that the state A contains the state A1, and that A1 owns the local event E. You can send event E to state A1 with this broadcast:

send(A.A1.E)

Undirected Event Broadcasts

An undirected event broadcast sends a local event to all states in which it is visible by using the name of the event as a condition action:

event_name;

or by calling the operator send without specifying a receiving state:

send(event_name)
event_name is a local event that is visible to the sending state.

When possible, use directed event broadcasts instead of undirected event broadcasts. Directed event broadcasts prevent unwanted recursion during simulation and improve the efficiency of generated code. For more information, see Avoid Unwanted Recursion in a Chart.

Diagnostic for Detecting Undirected Local Event Broadcasts

During simulation, Stateflow charts can detect undirected local event broadcasts. To control the level of diagnostic action, open the Configuration Parameters dialog box and, in the Diagnostics > Stateflow pane, set the Undirected event broadcasts parameter to none, warning, or error. The default setting is warning. For more information, see Undirected event broadcasts (Simulink).

See Also

Related Topics