Skip to content

Simulating the light switch model

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

Selecting Run As → Statechart Simulation in the context menu

The perspective changes from SC Modeling to SC Simulation. This perspective defines two additional views:

  • The Debug view at the top shows all running state machine instances and allows to select one of them. itemis CREATE allow multiple executions of the same state machine as well as parallel executions of different state machines at the same time.
  • The Simulation view on the right-hand side is used to raise events and to inspect and modify variables. Depending on your screen resolution and font size settings, you might not be able to spot the Simulation view by its name, because the tab containing it is quite narrow and might not provide enough space for displaying the title. Hover over the tabs to reveal their respective titles in a pop-up window. Figure "Light switch simulation in "off" state" is demonstrating this: The user has hovered the mouse pointer over a tab that is just displaying the starting letter ‘S’ of its title. However, a tooltip right beside the pointer is showing the tab’s full title “Simulation View”.

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

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 default entry’s show/hide symbol to display its contents.

Displaying event names in the statechart simulator's "Simulation" view

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

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.