Author Topic: Code generation in C with State Machine  (Read 10395 times)

Heero_91

  • EA Novice
  • *
  • Posts: 9
  • Karma: +0/-0
    • View Profile
Code generation in C with State Machine
« on: April 09, 2010, 07:41:03 pm »
Hi everyone,

I have to use (for the first time in my life) entreprise architect in order to generate source code with "only" a state diagram. I have to generate the code in C (no object please, this is not needed ;) )but I'm having trouble doing it on EA.

I have created a new project, with one package and one class diagram in it. In this class diagram I have created one class (with few attributs and one method). I have attached the state machine diagram to my class (using right click->add->statemachine) and i have put some states in it!

After that if I asked to generate the code in C, ths generation is done but i'm not getting the source code for my diagram. But if I'm asking for the same code in C++ (or C#, java...) I'm able to see my diagram.

Can you explain to me how to get my source code for the same diagram in C. I must have miss-done something, but I can't figure what :(

In the same time, if you can explain to me (or provide me a link/project example) about how to add action to states and transitions, it would be very nice.

Thanks a lot

Heero
« Last Edit: April 09, 2010, 07:43:20 pm by Heero »

deefer

  • EA User
  • **
  • Posts: 98
  • Karma: +0/-0
    • View Profile
Re: Code generation in C with State Machine
« Reply #1 on: April 09, 2010, 07:46:33 pm »
The code generation templates for "C" don't support the state machine generation if you don't enable the OO support.

You can customize them manually to do it, enable the OO support and take inspiration form its code templates (but it won't be easy, I tell you...)
Davide

Heero_91

  • EA Novice
  • *
  • Posts: 9
  • Karma: +0/-0
    • View Profile
Re: Code generation in C with State Machine
« Reply #2 on: April 09, 2010, 07:52:08 pm »
I'm not sure to understand very weel what you're saying... (I'm french ^^)

what's the "OO support"?

And if I activate it I have to customize? How so?

And "take inspiration firm (I guess from ^^) its code template"? I Really don't see what you're talking about :S

deefer

  • EA User
  • **
  • Posts: 98
  • Karma: +0/-0
    • View Profile
Re: Code generation in C with State Machine
« Reply #3 on: April 09, 2010, 07:55:47 pm »
OO = object oriented support (tools/options/C language)

Start to take a look at the help (look for code generation in the index)

Anyway, I'm right now trying to get some code working from the code generation for state machines in "C" but it is full of problems... my suggestion is: if it is a very simple state machine, then use the code generator, otherwise write it manually...

Heero_91

  • EA Novice
  • *
  • Posts: 9
  • Karma: +0/-0
    • View Profile
Re: Code generation in C with State Machine
« Reply #4 on: April 09, 2010, 07:59:12 pm »
I will talk with my project manager this afternoon and we'll see!

Thanks a lot anyway :)

Heero_91

  • EA Novice
  • *
  • Posts: 9
  • Karma: +0/-0
    • View Profile
Re: Code generation in C with State Machine
« Reply #5 on: April 09, 2010, 09:41:51 pm »
Ok, I have talked with my project manager and he still wants to use EA in C with code generation (maybe just for the moment, we'll see ...)

Anyway, I would like to ask, why I will have to modify the code template as you said before? (It seems a litle bit complicated, no?)

Heero_91

  • EA Novice
  • *
  • Posts: 9
  • Karma: +0/-0
    • View Profile
Re: Code generation in C with State Machine
« Reply #6 on: April 10, 2010, 01:12:14 am »
Sorry for the "flood" ...

I have also tried for hours to add source code to any of my state in the state machine but I can't! I think I'm not in searching in the right field or something like that, can you indicate me how to do that?

If you can also do the same with the transitions, it would be very nice.

Thanks a lot ...

Nizam Mohamed

  • EA User
  • **
  • Posts: 193
  • Karma: +1/-0
    • View Profile
Re: Code generation in C with State Machine
« Reply #7 on: April 12, 2010, 04:46:01 pm »

Aaron B

  • EA Administrator
  • EA User
  • *****
  • Posts: 941
  • Karma: +18/-0
    • View Profile
Re: Code generation in C with State Machine
« Reply #8 on: April 12, 2010, 04:52:20 pm »
Hi Heero,
Please confirm which edition of Enterprise Architect are you using. Code generation from behavioral diagrams is only supported in the Business and Software Engineering, Systems Engineering and Ultimate editions of Enterprise Architect.

Heero_91

  • EA Novice
  • *
  • Posts: 9
  • Karma: +0/-0
    • View Profile
Re: Code generation in C with State Machine
« Reply #9 on: April 12, 2010, 05:18:11 pm »
I'm using the trial edition of EA (Ultimate choosen each time, don't worry ;) ) and I'm able to generate the source code from my state machine in C, this is not the problem anymore ...

Now my problem is that I don't know how to put some behavior in my states. I would like, as an example, to put some conditions in order to know which transition the state needs to choose, or just the current behavior of the state (modify variable, print something ...). But I'm searching for this fonctionality since hours, and I'm unable to find anything :(

I would guess this is in the scenario that I have to put my comportement, but how to fill it? Is it some place else?

Also what is the interest of the "Files" option in each state?

Nizam Mohamed

  • EA User
  • **
  • Posts: 193
  • Karma: +1/-0
    • View Profile

Heero_91

  • EA Novice
  • *
  • Posts: 9
  • Karma: +0/-0
    • View Profile
Re: Code generation in C with State Machine
« Reply #11 on: April 13, 2010, 05:13:03 pm »
I have found this exact page yesterday so I have been able to get code for my transition, but I still get the main problem.

How to put behavior in my states? I have searched on the help, on the forum, on the EAexemple and so far I have found nothing :( . This is blocking me since days, so if you can just explain it to me.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13378
  • Karma: +563/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Code generation in C with State Machine
« Reply #12 on: April 13, 2010, 05:19:07 pm »
Heero

I have absolutely no clue how this will affect code generation, since I don't use that feature.
However if you want to add behavior in a UML way to states you need to use the "operations" option of the states.
There you will find a slightly modified dialog that allows you to add entry/do/exit activities.
In the behavior tab of those you can specify the behavior, or link an existing behavioral element.

Geert

PS. The "Files" tab is standard to all elements in EA. It allows you to link a document or url to it. I guess it's mostly used for documentation purposes.

Nizam Mohamed

  • EA User
  • **
  • Posts: 193
  • Karma: +1/-0
    • View Profile
Re: Code generation in C with State Machine
« Reply #13 on: April 13, 2010, 05:19:52 pm »
by defining do, entry or exit operations to the state, refer
http://www.sparxsystems.com/uml_tool_guide/modeling_with_uml/operationsmainpage.html

to specify behavior , refer
http://www.sparxsystems.com/uml_tool_guide/modeling_with_uml/operationsdetail.html

for an example refer "Project Models.Systems Engineering Model.Implementation Model.Software.C++.IO.SearchExternalMedia.ReadSerialPorts" Node in the supplied EAExample.eap file.

Heero_91

  • EA Novice
  • *
  • Posts: 9
  • Karma: +0/-0
    • View Profile
Re: Code generation in C with State Machine
« Reply #14 on: April 13, 2010, 06:23:34 pm »
Ok, thanks, it's finally generating source code in my states :D

I have the impression that I still have a lot of questions on this software (this is the first time in my life I'm using a soft in order to generate code...)

I was looking into the links you gave me, and I have a question... Why when you're creating your method attached to your state you need to put the "generated code" (because this is not generated at all, I'm not even getting the variables of my states, but this is not the problem ^^) into the area Behavior and not initial code? What is the purpose of the "initial code" in this case?

And I was wondering, how the state machine is able to move from Entry to Do or Exit, because I can't see the source code linked to this ... (actually I can see the enumeration, but not the changes :S )

I have the impression that for the moment we don't know the value of the "CommandType" and so we can't figure what is the comportement into the state diagram :(

Sorry for all those questions, but I really would like to understad how everything works in EA. ;)