SinelaboreRT Header Logo


It's better when it's simple!

User Tools

Site Tools


Tool Landing Pages


Designers Toolbox


Integrated state-chart editor with auto-layout

Focus on modeling and not on moving states around to create a nice looking diagram! Syntax aware text fields offer a comfortable way to specify actions, guards etc. When the diagram passed the model checker it can be directly simulated. Connect the diagram to the real hardware to monitor the state machine in action.

There are better ways to model state machines than using spread sheets!

In the past different μC manufacturers have published application notes about the benefit of using state machines for the design of embedded software. An example is the application note SLAA402 from Texas Instruments (TI). It suggests to generate source code based on a spread sheet table. Nowadays several affordable UML modeling tools are available supporting the efficient design of state machines in a graphical way. SinelaboreRT generates production quality source code from state diagrams created with many different UML tools. Give it a try!

Latest Changes


C# backend now available again

In an earlier version it was possible to generate C# code. This was not possible with the latest versions of the code generator, but is available now again with version 3.3.

To generate C# code call the code generator with the new command line flag -l csharp. All states are created into one source file. The file name is determined by the -o command line switch.

The generated code does not follow the state pattern as you might expect (if you are fa- miliar with common design patterns). The reason is that the machine code is completely generated and no hand-coding is involved. So the number of classes and files in your project is reduced to a minimum. The following figure shows the structure of the generated code. The classes marked with <generated> are generated from the code generator. Classes marked with <optional> are optional and must be provided by yourself if needed.

Figure: Structure of the generated C# code.

Microwave Oven Example in C#

A microwave oven is taken from the examples folder of the code generator to demonstrate the generator features. The example realizes a simple microwave oven and can be compiled with Microsoft Visual Studio1) on Windows2). The next figure shows the state diagram of the oven. It was created with the Cadifra UML editor.

A simple hardware abstraction layer provides helper functions like a timer etc. You can see how it is called from the state machine (e.g. in an entry action) as hal.ovenOff().

You have the option to either generate an own state class per state or inline all the entry/do/exit action code directly into the generated state machine code. As there is no need for separate state classes (e.g. complex and long actions) they were inlined in this example. The generation process can be controlled with a simple configuration file as shown below. You can also see that we provide an own base class for the Oven class to implement some special functions directly usable from the state machine.


To generate code from the diagram call the generator as follows:

java -Djava.ext.dirs=../bin/ -jar  "../bin/codegen.jar" -p CADIFRA -l csharp -o Oven oven.cdd

The generated code looks as follows:

namespace OvenMachineNS
  public class Oven : OvenBase
    public enum States : int{
    public enum Events : int {
    public int ProcessEvent(Events msg){
      int evConsumed = 0;
      if(m_initialized==false) return 0;
      /* action code */
      /* just a comment */
        switch (stateVar) {
          case States.Super:
            switch (stateVarSuper) {
              case States.Idle:
                    /* Transition from Idle to Cooking */
                    /* Action code for transition  */
                    /* OnEntry code of state Cooking */
                    /* adjust state variables  */
                    stateVarSuper = States.Cooking;
                    /* Intentionally left blank */
                  } /*end of event selection */
                  /* Intentionally left blank */
                } /*end of event selection */
              break; /* end of case Idle  */
              case States.Cooking:
          break; /* end of case Super  */
            /* Intentionally left blank */
        } /* end switch stateVar_root */
    return evConsumed;
  } // end of namespace

Finally start the generated exe file and play with the microwave oven. First increment the cooking time. Then start cooking by closing the door.

The sinelabore code generator provides much more features than just code generations. Before generation an extensive check is performed to ensure your diagram is correct (e.g. each transition has an associated event, all state names are unique …). You can add trace code if needed, simulate the state machine, generate test cases and more.

If you want to try out the example yourself download the code generator demo. The oven can be found in the examples folder.

How do you like this article?
 stars  from 3 votes
1) , 2) Copyright Microsoft Cooperation

Leave your comments

, 2015/04/16 00:30

Write more, thats all I have to say. Literally, it seems as though you relied on the video to make your point. You clearly know what youre talking about, why throw away your intelligence on just posting videos to your weblog when you could be giving us something enlightening to read? dbgbkebgkgeedbdb

wiki/news/16aug2013.txt · Last modified: 2015/05/01 21:01 by pmueller