Reply To:


There are two source code generation templates for state machines. One (called "StateMachine") is for behavior state machine diagrams, another template (called "ProtocolStateMachine") is for protocol state machine diagrams.

The type of state machine diagram can be set in the Diagram Properties dialog - right click somewhere on free space in a diagram, choose Properties from the context menu, then choose State Machine tab and in the Type group choose Behavior or Protocol type.

In a behavior state machine, you should use Transition tool for transitions and for protocol state machine, you should use Protocal Transition. If you use the context bar (under a selected element) to add new states, the correct transition type is chosen automatically according the state machine type.

The correct way how to create a new protocol state machine and generate the source code for it is:

1. Create a class in a class diagram and select it (or select an existing class) - the class should have some operations

2. Right click on the class and choose Add Nested Diagram

3. Choose State Machine diagram in New Diagram dialog and type its name

4. Right click on free space in this state machine diagram

5. Choose Properties

6. Open State Machine tab

7. Change the state machine type to Protocol

8. Add states and transitions to your diagram

9. In Ribbon, choose Process tab and click on Source Code in Generation group

10. Check your state machine diagram in the project tree in Source Code Generation dialog

11. Change language to C#

12. Change template to ProtocolStateMachine

13. Click on Generate

14. The source code for your state machine should be generated

In case of any other questions feel free to let me know.

Dusan Rodina - 27 July 2017 13:43:33

New Comment

You can use these formatting tags: [b]bold[/b] [i]italic[/i] [u]underline[/u] [url][/url] [code]some code[/code] [quote]quoted text[/quote] [list]one list item per line[/list]