Stateflow | ![]() ![]() |
Labeling States
Every state has a label. A state's label specifies its name and the actions executed when the state is entered, exited, or receives an event while it is active. How to edit the label and the contents it requires are described in the topics that follow.
For more information on state label concepts, see the following:
Editing a State Label
Initially, a state's label is empty. Stateflow indicates this by displaying a ? in the state's label position (upper left corner).
Label unlabeled states as follows:
To apply and exit the edit, deselect the object. To reedit the label, simply left-click the label text near the character position you want to edit.
You can also edit the state's label through the properties dialog for the state. See Changing State Properties.
State Label Format
State labels have the following general format.
name
/
entry:entry actions during:during actions exit:exit actions onevent_name
:on event_name actions
The entries in this format have the following meanings:
Entry |
Description |
name |
A unique reference to the state |
entry actions |
Actions executed when a particular state is entered as the result of a transition taken to that state |
during actions |
Actions that are executed when a state receives an event while it is active with no valid transition away from the state |
exit actions |
Actions executed when a state is exited as the result of a transition taken away from the state |
on event_name actions |
Actions executed when a state is active and the specified event event_name occurs See Defining Events for information on defining and using events. |
Entering the Name
Enter the state's name in the first line of the state's label. Names are case sensitive. To avoid naming conflicts, do not assign the same name to sibling states. However, you can assign the same name to states that do not share the same parent.
Entering Entry Actions
Entry actions begin on a new line and consist of the keyword entry
(or just en
), followed by a colon, followed by one or more action statements on one or more lines. You must separate statements on the same line by a comma or semicolon.
Note You can also begin a state's entry action on the same line as the state's name. In this case, begin the entry action with a forward slash (/) instead of the entry keyword. |
Entering During Actions
During actions have the same format as entry actions except that they begin with the keyword during
or dur
.
Entering Exit Actions
Exit actions have the same format as entry actions except that they begin with the keyword exit
or ex
.
Entering On Event_Name Actions
On
event_name
actions specify an event handler for a state. They have the same format as an entry actions except that they begin with the keyword on
, followed by the name of the event, followed by a colon, for example:
A Stateflow diagram can respond to multiple events, with either the same or different actions, when a state is active. If you want more than one type of event to trigger the same action, specify on
event_names
, where event_names
is a comma-separated list of the events that trigger the actions, for example:
If you want different events to trigger different actions, enter multiple on
event_name
blocks in the state's label, each specifying the action for a particular event or set of events, for example:
Note
Use a during block for a state to specify actions to take in response to any visible event that occurs while that state is active without a valid transition to another state (see Entering During Actions).
|
![]() | Changing State Properties | Outputting State Activity to Simulink | ![]() |