This webinar has completed, the recording will be posted shortly.

Overview

How can you generate and implement code from an Executable State Machine to build a web based prototype?

Enterprise Architect allows you to model, build and simulate an Executable State Machine. We'll use an Audio Player example to show how you can model system behavior and generate code from an Executable State Machine.

Not only does the simulation help us to better understand system behavior, but it can also produce JavaScript code that allows us to develop a convenient web application for a virtual Audio Player.

In this Webinar, you will learn how to:

REGISTER TODAY!

Don't miss this opportunity to learn more about Enterprise Architect

Session 1

Melbourne Wed 16 August 08:00 am
New York Tue 15 August 18:00 pm
Los Angeles Tue 15 August 15:00 pm
London Tue 15 August 23:00 pm
Auckland Wed 16 August 10:00 am

Session 2

Presenters

Scott HebbardSparx Systems

Explore the webinar resources

Questions & Answers

General

Enterprise Architect 13.5, Build 1351 was used throughout the webinar.

The Enterprise Architect User Guide provides a comprehensive overview of model Simulation. For more information, please see the Help topic Model Simulation.

Code Generation for Executable State Machines is supported in the Ultimate and Systems Engineering editions of Enterprise Architect. For reference, see our Compare Editions page.

Yes. We have used the EAExample model for your convenience. A copy of the EAExample model is shipped with every copy of Enterprise Architect.

The file is EAExample.eap, which is typically found in the installation directory. On Windows, a typical file path would be:

C:\Program Files (x86)\Sparx Systems\EA

The path of the CD Player Model in the Project Browser of the EAExample model is:
Example Model.Model Simulation.Executable State Machine.Example: CD Player.CD Player Simulation.

The code generation capabilities are available in Enterprise Architect 13 and above. Enterprise Architect has been capable of simulating a State Machine for some time.

Yes. We email all registered attendees to inform them about the publication of the webinar. The back catalog of all previous webinars is available via our Webinar Library.

The file is EAExample.eap, which is typically found in the installation Directory:
C:\Program Files (x86)\Sparx Systems\EA
The path in the Project Browser is:
Example Model.Model Simulation.Executable State Machine.Example: CD Player.CD Player Simulation.

Simulation and Code Generation

Five languages are currently supported. These languages include C, C++, C#, Java and JavaScript.

Yes. A Regular Expression and CD example is available from the Help topic Example: Simulation in HTML with JavaScript.

ASP.net is not currently supported for automatic code generation from an Executable State Machine. However, other languages including C, C++, C#, Java and JavaScript are supported.

Yes.

Yes. There are two ways:

  1. You can modify the templates so all further code generation will use the customized template. Use the ribbon Code | Configure | Code Template Editor. In the Language field choose one of: STM_C, STM_C#_Structured, STM_C++_Structured, STM_JAVA_Structured, STM_JavaScript
  2. You can modify the generated code directly. When you want to simulate with the modified code, do NOT 'Generate', which will overwrite the customized code. Just 'Compile' (not needed for JavaScript) and 'Run'.

Yes. You can broadcast an event to all instances or send an event to a specific instance.
Refer to the example in the Help topic Example: Deferred Event Pattern.

In order to support generating code for multiple languages with the same model, we introduced two macros:
%SEND_EVENT(Event Name In Quotes, CONTEXT_REF(instance name))%
%BROADCAST_EVENT(Event Name In Quotes)%

Example usage:
%SEND_EVENT("NEW_REQUEST", CONTEXT_REF(server))%
%BROADCAST_EVENT("NEW_REQUEST")%

You can define operations with parameters in the Class (owning the StateMachine), then call the operations in the State's behavior or transition's effect by specifying arguments.

For example, MyClass defines an operation int AddTwoNumbers(int MyParam) and three attributes: int nOne; int nTwo; int nThree
Now in an InitState's entry behavior, we specify the initial code as:
nOne = 5;
nTwo = 6;

In MyState's entry behavior, we specify the initial code as:
nThree = AddTwoNumbers(nOne, nTwo);

When this state is active, the runtime value of nThree will be 11.

Other

A Block is of type Class, so yes, if you set up the Block with the necessary Attributes and Operations it will use these during code generation.

The Simulation generates code based on the StateMachine model. That model can have triggers. These triggers can be set to be from external devices like PLCs, but you do need to alter the code generated to set your interface to them.

See the section Leveraging existing code, in the Help topic Code Generation for Executable StateMachines.

Yes. This is explained in the Help topic Code Generation for Executable StateMachines.

You need to ensure that you have your code generation configured to interface with your IDE and you need to change the Element.Language from Javascript to C++ in the <<Executable StateMachine>> Artifact.

Also for C++, note that statements use a different notation:

Javascript: this.currentTrack=0;
C++: this->currentTrack=0;

So you do need to edit these statements in the Operations and Transitions.

We are considering providing a new feature to enhance this changeover.

Enterprise Architect supports forward engineering of behavioral models. It does not support reverse engineering them for obvious reasons.
If you do want to modify the code, then it is best to do it in the model and then generate this out.

Not directly as part of the Simulation process.
However, Sequence diagrams can be generated from the code using the Enterprise Architects Visual Execution Analyzer. See the Help topic Recording.

If you are updating the generated code outside of the model then, as there is no reverse engineering of behavioral model code, this will not be updated in the model. So, if you are modifying code, it is best you either do this in the model or assume the modeling is complete and do this separately to the modeling.

Sparx Systems BPSim MDG supports statistical analysis of simulations. As StateMachines are more about timing, logic and debugging these statistics are not recorded for an Executable State Machine simulation.

Yes.

Enterprise Architect supports interfacing with OpenModelica for SysML Parametric simulation. It does not provide OpenModelica support for Executable StateMachines.

For a standard Behavioral model simulation in Enterprise Architect, you can call an Activity diagram from a State in a StateMachine diagram, as part of the simulation. For the simulation via Executable StateMachines - this only supports code generation of StateMachines, not other Behavioral models such as Activities.

Enterprise Architect's Behavioral model code generation does support generating Activity, Sequence and StateMachines to code. It does not support simulation.

The Executable StateMachine Artifact may appear redundant when only executing a single instance of a Class containing a StateMachine. The purpose of the Artifact is to ensure you can simulate multiple instances of your Class/StateMachine by creating multiple Artifacts to cover them.

For examples of using multiple instances see the Help topic Example Executable StateMachine.

In the EAExample.eap repository supplied with Enterprise Architect.

See EAExample.eap file in the directory ...\Program Files (x86)\Sparx Systems\EA.

See the package Example Model.Model Simulation.Executable State Machine.Example: CD Player.

Automated Test Cases can be generated in Enterprise Architect from Use Case Scenarios. If, in your modeling, you have defined a set of Use Case Scenarios prior to and covering the creation of your StateMachines, then these Test Cases can be generated from the Scenarios for use with the StateMachines.

Enterprise Architect supports forward engineering of behavioral models. It does not support reverse engineering of them for obvious reasons.
If you do want to modify the code, then it is best to do it in the model and generate this out.
However, you can import the code, but it is not recommended.

Yes using multiple Artifacts representing the same StateMachine. For details, refer to the Help topic Executable StateMachine Artifact.

After generating the code you can modify it using Enterprise Architect's code editor, and add new functions or call external functions as you would modify any code in an IDE. You can also modify the code in any IDE or editor that supports your target language.

Yes.

Code Generation for Executable State Machines is supported in the Ultimate and Systems Engineering editions of Enterprise Architect. For a detailed comparison of Enterprise Architect editions, see our Compare Editions page.

Code Generation for Executable State Machines is supported in the Ultimate and Systems Engineering editions of Enterprise Architect. . For a detailed comparison of Enterprise Architect editions, see our Compare Editions page.

Enterprise Architect supports exporting the model to XMI format, but not JSON format.

Yes.

It is the execution of the generated code.