预订演示

该网络研讨会已完成, 录音将很快发布.

概览

如何从可执行状态机生成和实现代码以构建基于Web的原型?

Enterprise Architect允许您建模,构建和模拟可执行状态机。 我们将使用音频播放器示例来说明如何建模系统行为并从可执行状态机生成代码。

仿真不仅有助于我们更好地了解系统行为,而且还可以生成JavaScript代码,使我们能够为虚拟音频播放器开发便捷的Web应用程序。

在此网络研讨会中,您将学习如何:

立刻注册!

不要错过这个机会来了解有关Enterprise Architect的更多信息

第一场

墨尔本 Wed 16 08 08:00 am

第二场

演讲者

Scott Hebbard交际经理
Sparx Systems

探索网络研讨会资源

问题和答案

常见

在整个网络研讨会中使用了Enterprise Architect 13.5,Build 1351。

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.

仿真和代码生成

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, 其他 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.

其他

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 其他 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.