Please note : This help page is not for the latest version of Enterprise Architect. The latest help can be found here.

Prev Next

Modeling for Stateflows

You have several options when creating a StateMachine diagram that is intended to be rendered as a Stateflow diagram. These include which elements and connectors can be used, the placement of the StateMachine, where code can be defined in the model, and what format of code can be used.

StateMachine Placement

When creating a model to be generated as a Stateflow diagram, the StateMachine diagram must be placed under a SysML Block and have a child StateMachine element, with a StateMachine diagram under that StateMachine element.

For example, in this case the Block 'Control' has a child StateMachine named 'ControlStateMachine', which has a child StateMachine diagram 'ControlStateMachine':

Note that the Block must only contain a StateMachine diagram; it should not contain other diagrams.

Defining code

There are a number of options for placing script in a StateMachine model. The key considerations for this are: what is the format of the script, and where can it be placed?

Code format

When you write any valid SysML code it will be translated to valid Stateflow code. The SysPhS specification defines the Modelica maths language as the 'standard', which is what Enterprise Architect accepts as code snippets in the StateMachine diagram, and translates these to the MATLAB/Stateflow equivalent. For more details refer to section 10 of the OMG SysPhS specification.

Code placement

Internal to a State and in conformance with the UML specification, Stateflow supports the three standard Operations:

  • Entry
  • Exit
  • Do

Each of these can contain code, which is defined in the State's Operation under Behavior. For example, this is a code snippet for an Entry:

On Transitions there are three key options for using code:

  • Transition Guard
  • Transition Effect
  • Trigger

For example, this is a condition statement as defined in a Transition Guard:

Using Block Properties

For the code, the Block Properties such as constants and Ports can be referenced within the script. In the case of the Ports, the details being input into the Block are derived using the input Port name, and similarly values can be assigned to a variable of the same name as the output Port.

For example:


These SysML StateMachine features are not available in Stateflow:

  • Deep History state
  • History states that have out-going transitions (that is, initial States) to be used on all default entries
  • Fork/Join
  • Sync
  • Junction (only Choice - Junction will be replaced with Choice where possible)
  • Entry/Exit points
  • References to other StateMachines; Stateflow can do child StateMachines but they can't be referenced again
  • Only one StateMachine per SysML Block

Learn More