Sinelabore

State Diagram Editor Introduction Part I#

Overview#

In this guide you learn how to use the SinelaboreRT graphical editor and generate code from the resulting state diagram. To see the whole process first, from the empty editor to running C code, watch the 4-minute film on the editor page.

State machines show the dynamic behavior of an application. They are graphs of states and transitions describing responses to events depending on the current state. State machines have been used for decades in hardware design and are now also widely used in software development, especially in embedded real-time systems.

Start the editor: an empty machine
1 / 10 · Start the editor: an empty machine
Right-click the root node and choose **Insert State**
2 / 10 · Right-click the root node and choose Insert State
Name the state and add its entry and exit code
3 / 10 · Name the state and add its entry and exit code
S1 is drawn, and an initial state leads to it
4 / 10 · S1 is drawn, and an initial state leads to it
A second state, S2
5 / 10 · A second state, S2
Right-click S1 and choose **Insert Transition**
6 / 10 · Right-click S1 and choose Insert Transition
Event `ev1`, an action and the target state S2
7 / 10 · Event ev1, an action and the target state S2
The transition from S1 to S2
8 / 10 · The transition from S1 to S2
The finished diagram with a choice and a final state
9 / 10 · The finished diagram with a choice and a final state
The code window: code and settings for the whole machine
10 / 10 · The code window: code and settings for the whole machine

An important aspect of state machines is that the design can be directly transformed into executable code. This means there is no gap between design and implementation.

The SinelaboreRT state machine editor is part of the code generator, not a separate package. Depending on command line options, the editor, simulator, or code generator is started.

Like the code generator, the visual editor can be used across Windows, Linux, and macOS.

The state machine editor is designed to create state machine designs within minutes. Compared to general-purpose UML tools, the number of required clicks and time is significantly lower.

Installation#

To use the visual editor, the following software is required:

  • SinelaboreRT: no installation is needed. The ZIP file contains a bin folder with the packed Java program (jar).
  • Java runtime environment: required because the editor is written in Java. Download from jdk.java.net (Java 17 or newer).

The editor draws the diagrams itself; no further software is needed.

For the examples below, assume tools are installed directly under C:\ on Windows.

C:\>dir
...
16.01.2025  20:46    <DIR>          jdk-17
24.10.2026  17:35    <DIR>          sinelaboreRT7.5
...

State Machine Editor#

Overview#

The editor uses a tree-based approach instead of manual graphical layout. Diagram rendering is generated automatically, so no time is spent moving elements around. Dedicated fields support syntax highlighting and guard/action/entry/do/exit definitions.

Once a diagram is ready, code can be generated directly, or the model can be saved and processed by command line generation later (for example in a Makefile).

Starting the editor for the first time#

Open a command window (Windows) or terminal (Linux/macOS) and run:

c:\jdk-17\bin\javaw.exe -cp "c:/sinelaboreRT7.5/bin/*" codegen.Main -p ssc -E

-E starts the state chart editor. -p ssc selects the native editor model format (XML-based and human-readable).

If you have a license, name it in a codegen.cfg in your home directory, so every project finds it:

LicensePath=...

The editor opens with an empty workspace.

The editor after startup, with numbered markers for its parts
  1. Check: checks the model for errors.
  2. Generate: generates code in the language shown in the status bar (15).
  3. Undo and redo.
  4. Zoom in and out.
  5. Code: code and settings for the whole state machine, see Generating code.
  6. State Details and Transition Details: how much text states and transitions show in the diagram.
  7. Whole chart: draws the whole hierarchy, not only the selected level.
  8. The state tree: build the machine here with the context menu.
  9. Event Overview: every event of the machine and the fields it carries.
  10. The diagram, drawn automatically from the tree.
  11. The properties of the selected state or transition.
  12. The output: messages of the model check and the trace of the simulation.
  13. The model file.
  14. The configuration file in use.
  15. The language code is generated for.
  16. The port for remote control of the simulation, off by default.

Creating a state diagram#

In this section we build the diagram shown at the end of this section.

Adding states#

Select the root node, right click, and choose Insert State. At minimum, specify a unique state name. Add entry and exit code as shown in the final example, then click OK.

The context menu with Insert State, and the dialog for a new state with numbered markers
  1. Right-click the root node and choose Insert State.
  2. The state name, unique in the machine.
  3. Entry code: runs when the state is entered.
  4. Action/Do code: runs while the machine is in the state.
  5. Exit code: runs when the state is left.
  6. State notes: documentation only, not part of the generated code.
  7. History: whether the state remembers its last substate.

The first state appears and an init state is created automatically if needed. Add state S2 the same way.

Adding transitions#

Right click the state in the state tree where the transition starts (here S1), then choose Insert Transition. Select the target state (here S2) and add event, guard and action as needed.

For an init-to-default transition, no triggering event is needed.

The context menu with Insert Transition, and the transition dialog with numbered markers
  1. Right-click the state where the transition starts and choose Insert Transition.
  2. The event that triggers the transition. Transitions from an initial state need none.
  3. Edit… opens the fields the event carries, its payload.
  4. Guard: the transition is taken only when it is true.
  5. Action: code that runs when the transition is taken.
  6. The target state.
  7. Layout hints: where the line leaves and enters a state. Normally Auto.
  8. Conditional: the event text is a boolean expression in the target language, for example i>0. Do not mix events and conditional triggers in one diagram.
  9. Inner: the state is not left, so no exit and entry code runs.
  10. Exclude: the event is defined elsewhere, for example by an RTOS or a library, and is left out of the generated event list.

Adding a final state#

Add a final state from the root context menu. This is similar to adding a normal state, but without editable properties.

Adding a choice#

A choice represents dynamic branching. It must have one incoming transition and at least two outgoing transitions. Every outgoing transition needs a guard, and one guard should be else (default path).

Add a choice from the root context menu, then:

  • add one transition entering the choice (with trigger)
  • add two transitions leaving the choice (with guards)
  • ensure one guard is else

First diagram done#

After completion, the diagram looks like this:

Use Save As and save as manual.xml.

The finished diagram with an initial state, two states, a choice and a final state

To reopen directly with your project:

c:\jdk-17\bin\javaw.exe -cp "c:/sinelaboreRT7.5/bin/*" codegen.Main -p ssc -E manual.xml

Generating code from your first state diagram#

Unlike many UML tools, the editor enforces valid diagrams (for example transition trigger presence and unique state names). If inconsistencies exist, the model checker warns and blocks save/generation until fixed.

Before generating code:

  1. Open the Code window and configure target language and user code sections.
  2. Define handler signature:
HsmFunctionWithInstanceParameters=yes
HsmFunctionWithEventParameter=yes
  1. Add additional instance attributes via the Attributes button if needed.
The code window with numbered markers, and the handler signature dialog
  1. Header code: includes, definitions and globals at the top of the generated file.
  2. Action code: runs at the start of the state machine function.
  3. Post action code: runs just before the function returns.
  4. The language of the generated code.
  5. Handler Signature opens the dialog on the right: the parameters of the state machine function.
  6. Attributes: additional variables in the machine’s instance data.

If validation is clean, press generate. Files are written next to the project file.

D:\>dir
 Verzeichnis von D:\

30.01.2021  17:37               137 codegen.cfg
30.01.2021  17:51             2.209 manual.c
30.01.2021  17:51               650 manual_ext.h
30.01.2021  17:51             2.232 manual.h
30.01.2021  17:51             1.990 manual_dbg.h

Generated files:

  • manual.c state machine implementation
  • manual_ext.h machine event definitions
  • manual.h state machine header
  • manual_dbg.h debugging support

Compiling the first application#

Use a small main.c to stimulate the generated machine:

#include <stdio.h>
#include <stdint.h>
#include "manual_ext.h"
#include "manual.h"

MANUAL_INSTANCEDATA_T instData = MANUAL_INSTANCEDATA_INIT;

uint8_t i=0;

int main(void){
    manual(&instData, MANUAL_NO_MSG);
    printf("--\n");
    manual(&instData, ev1);
    printf("--\n");
    manual(&instData, ev2);

    printf("Now we set i>0\n");
    i=1;
    manual(&instData, ev2);

    // From now on no reaction is possible anymore because
    // the machine is in a final state
    manual(&instData, ev2);
    manual(&instData, ev1);

    return 0;
}

Compile:

D:\>g++ -Wall -pedantic main.c manual.c -o manual.exe

Run:

D:\>manual.exe
Entry S1
--
Exit S1
ev1
Entry S2
--
Exit S2
ev2
Entry S2
Now we set i>0
Exit S2
ev2
i>0

D:\>

Wrapping up#

You learned how to install SinelaboreRT, model a first state machine, generate code, and run it.

As a next step, modify the diagram, regenerate code, and explore more options in the code generator configuration and command line parameters.

Have fun!

Go to part II

All details are described in the code generator manual (PDF).