Five-minutes tutorial

The five-minutes tutorial gives you a brief introduction into modeling state machines with YAKINDU Statechart Tools by a simple example. It models a light switch, which has the states on and off. Operating the switch repeatedly turns the light on, off, back on again, and so forth. You can simulate this behavior in a dynamic statechart model (state machine model). Here’s how this looks like:

Interactive light switch statechart simulation

Interactive light switch statechart simulation

In the simulation screenshot above, the light switch is currently in the on state. To toggle the light switch, the user clicks on operate on the right-hand side of the window.

Importing light switch example

Now try this for yourself. We are assuming that you have already installed and started YAKINDU Statechart Tools. If you don’t, please see the Installation Guide for details.

  1. If the „Welcome” page is still open, close it.

    Closing the "Welcome" page

  2. In the main menu, select File → New → Example….
  3. In the dialog, select YAKINDU SCT Examples, then click Next >.
  4. The example wizard opens. If needed, follow the instructions to download the examples repository.
  5. On the left-hand side of the example wizard, select Light Switch Example, then click Finish.
  6. The sample project named light_switch is created.
  7. In the project explorer on the left-hand side of the window, open the light_switch project by clicking on the small triangle left from the project name („light_switch”). Also open the model folder.

    Expand project

  8. The light switch statechart is defined in the file light_switch.sct. Double-click on this file to open the model.

Simulating the light switch

  1. Right-click on light_switch.sct and select Run As → Statechart Simulation in the context menu.
  2. The simulation starts and shows the light switch model in its off state. The rectangle named Off is highlighted in red, meaning it is the active state.

    Light switch simulation in "off" state

  3. At the right-bottom side of the window, the simulation view is located. In this view, you can change variable values and raise events during a simulation run. Click on the small triangle left from internal to unfold the operate link. This link represents the operate event to switch the light on or off.
  4. Click on the operate link. The active state changes accordingly from Off to On.

    Light switch simulation in "on" state

  5. Click on operate again to switch off the light.

Generating statechart code

You have developed and tested your statechart model, and now you need it as a C, C++, or Java implementation? YAKINDU Statechart Tools can create it for you.

As an example, we will take the light switch statechart and generate Java source code from it. Please proceed as follows:

  1. In the project explorer, right-click on light_switch.sct and select New → Code Generator Model in the context menu.

    Creating a new code generator model

  2. In the dialog, replace default.sgen by light_switch.sgen, then click Next >.
  3. In the next dialog, check the checkbox left from light_switch.sct, then click Finish.
  4. Java classes implementing the statechart model are generated. You can find the generated source code in the folders src and src-gen within the light_switch project.

    Generated Java source code

That’s it. If you want to know more, take the time and work through the Comprehensive Tutorial.