Simulating a statechart model means to execute it, raise events manually, have time-based and other events being triggered automatically, and observe the model’s behavior.
Start the simulation by right-clicking on the LightSwitch.sct file in the project explorer and selecting Run As → Statechart Simulation:
Selecting Run As → Statechart Simulation in the context menu
The perspective changes from SC Modeling to SC Simulation. This perspective defines two additional views:
Not surprisingly, the simulation starts at the initial state and then transitions to the Off state immediately. The latter becomes the active state now. It is highlighted by a yellow background:
Light switch simulation in „off” state
Now that the light switch is off, let’s turn the lights on by operating the switch. In the simulation, we will have to raise the operate event. How can we do this?
In the Simulation view at the right-hand side of the Eclipse workbench, click on the internal entry’s show/hide symbol to display its contents.
Displaying event names in the statechart simulator’s Simulation view
The operate event is shown. Click on it to raise the event, i.e., to operate the light switch.
The transition arc leading from the Off state to the On state flashes briefly in red, and then the On state becomes active. Its background color changes to yellow while the Off state’s background color becomes normal again.
Light switch simulation in „on” state
Click on operate again, and the active state changes back to Off. Click on operate several times and enjoy watching the state machine’s behavior.
Stop the simulator by clicking at the little red termination button in the toolbar at the top.