Generate production quality code from state diagrams created with Magic Draw#
SinelaboreRT generates readable and maintainable code from hierarchical UML state machines. With its C backend it is well suited for embedded real-time and low-power applications. With C++, Python and Java backends it is also useful for server and desktop software.
Key Features#
- Automated robustness checks before code generation
- No runtime environment needed
- Works with any CPU and with/without OS or RTOS
- Focus on embedded real-time and high-availability systems
- Fits foreground/background and RTOS-based designs
- No gap between design and code
- Support for automatic test-case generation
- Interactive and batch simulation
- Optional trace code generation
- Generated code works well with static code checkers
Supported State Machine Elements#
A rich set of state machine features is available to model complex behavior:
- Hierarchical states
- Signal events with event name, guard and action
- Initial and final pseudo states
- History states (deep, shallow)
- Choices and junctions
- Constraints
These are the general modeling and code generation capabilities. The next section shows how to apply them with Magic Draw.
Watch the code generator in action#
The following example shows how the code generator works using a simple microwave oven.
Requirements#
- Cooking time can be adjusted from 0 s to 60 s.
- Cooking starts if the cooking time is > 0 s and the door is closed.
- If the door is opened during cooking, the microwave generator is switched off and the cooking time stops.
- Cooking continues if the cooking time is not over and the door is closed again.
- Cooking stops if the cooking time is over or the time is adjusted to zero.
- Cooking time and power can be changed at any time.
The state machine and class diagram below show a possible solution.


To generate C code, export your model to XMI and call the code generator as follows:
java -cp "../../bin/*" codegen.Main -l cx -p md -t "Model:oven_package:oven" -o oven oven.xmi.xmlAfter model validation (for example duplicate-state checks), full state machine code is generated.
Generated output files (example):
oven.coven.hoven_ext.h
In the examples folder you will find complete sample code ready to test and expand.
More Information#
- Model-based testing of state diagrams
- Interactive simulation and trace generation
- Code generation manual (PDF)
- Download demo
Magic Draw How-To#
I don’t see the on-entry/on-exit/do code in my state diagram#
Since Magic Draw 19, it is necessary to copy your code to the body text.

Is it necessary to specify an action name for on-entry/on-exit/do code?#
If there is text in the name field, that text is used for code generation. If the name field is empty, the body part is used for code generation. The body text can be longer than one line.
