Sparx Systems Forum
Enterprise Architect => General Board => Topic started by: Ian Kirwan on June 28, 2016, 11:26:36 pm
-
Hi all,
Just wondering if anyone can help on a matter of communication between concurrent states. I have a state machine with 2 composite concurrent states that I wish to signal between. In my days using Simulink/Stateflow I would simply create an event and refer to it from the sending concurrent state in an action expression and refer to it from the receiving concurrent state in a trigger expression. How do I achieve this in EA? I can create a trigger event easily enough in the recipient transition but I don't know how to send the event from a transition action. The options I seem to have is to select a behaviour, which seems to only allow me to select activities or I can type the name of the trigger event into the transition effect text box, but this seems like purely a text exercise without any connection to an actual event in the model. Am I expecting too much from EA?
TIA
Ian
-
Have picked up some info from the example model :
Project Model.Model Simulation.State Machine Models.Music Player.MusicPlayer
The model however is woefully under documented. Barely a single description/note field filled out if any :-[
The model does show event reception using triggers and signals but I don't see any examples of events being sent by the example model so far :-\
-
I don't use it, but I believe there are some video tutorials on Sparx site. Might as well be wishful thinking ;-)
q.
-
It's a shame. EA state machines are so close, frustratingly so, but no banana. May have to recommend the company ditch EA in favour of Simulink/Stateflow. Sparx really needs to brush up its EA documentation IMO. Intra-state machine communication (concurrent states) info is just none existent. Somehow you have to try to cobble it together out of activity references, triggers and signals. Stateflow is intuitive and works in this respect. Perhaps Sparx's goal was just to meet the UML spec, but that certainly is not enough for formal and functional state machines and inter communication :-\
-
There is a simulation whitepaper with an example model available on:
http://community.sparxsystems.com/white-papers/692-state-machine-simulation-in-enterprise-architect
This has a concurrent state, but has state transitions triggered from UI buttons.
See also the Activity Signals example in the EAExample model:
Project Models.Model Simulation.Activity Models.Sending Signal
-
You can use Executable Statemachine.
Create a class element MyClass, from Project Browser | Context menu | Add | Statemachine
- Initial1, transition to State1, transition to Final1
- Enlarge State1 | context menu | advanced | Define Concurrent Substates, create region1, region2
- Inside region1: Initial2, transition to Stete2, transition(triggered by BBB) to State3, transition to Final2
- Inside region2: Initial3, transition to Stete4, transition (triggered by AAA, Effect: %BROADCAST_EVENT("BBB")%) to Final3
Then create an Executable Statemachine artifact, enlarge it, Ctrl + Drag MyClass and drop as a Property, name it Part1.
Set the artifact's language, JavaScript (you can also set to Java, C++, C#, C if you have a compiler).
Context menu on Artifact | Code Engineering | Executable Statemachine | Generate, Build and Run | Specify a path for the source code | Generate
The simulation will start and State2 and State4 are the two active states in the concurrent regions. Open Simulate Events (Trigger) window, double click "AAA", which will trigger event "AAA" and transition from State4 to Final3 takes effect, during which, an event "BBB" will be broadcasted and cause State2 exit and transition to State3. The full trace are available in the Debug window.
[21383023] Part1[MyClass].Initial1_280__TO__State1_127 Effect
[21383024] Part1[MyClass].StateMachine_State1 ENTRY
[21383025] Part1[MyClass].StateMachine_State1 DO
[21383026] Part1[MyClass].Initial3_285__TO__State4_130 Effect
[21383027] Part1[MyClass].StateMachine_State1_State4 ENTRY
[21383028] Part1[MyClass].StateMachine_State1_State4 DO
[21383029] Part1[MyClass].Initial2_282__TO__State2_128 Effect
[21383030] Part1[MyClass].StateMachine_State1_State2 ENTRY
[21383030] Part1[MyClass].StateMachine_State1_State2 DO
[21384117] Blocked
[21386083] Part1[MyClass].StateMachine_State1_State4 EXIT
[21386085] Part1[MyClass].State4__TO__Final3_287_131 Effect
[21386640] Part1[MyClass].StateMachine_State1_State2 EXIT
[21386647] Part1[MyClass].State2__TO__State3_129 Effect
[21386649] Part1[MyClass].StateMachine_State1_State3 ENTRY
[21386650] Part1[MyClass].StateMachine_State1_State3 DO
[21387185] Part1[MyClass].StateMachine_State1_State3 EXIT
[21387192] Part1[MyClass].State3__TO__Final2_284_133 Effect
[21387700] Part1[MyClass].StateMachine_State1 EXIT
[21387707] Part1[MyClass].State1__TO__Final1_288_132 Effect
The key point is the effect expression:
%BROADCAST_EVENT("EventName")%
If you want to send the event to a specific context (E.g. Your artifact has 2 contexts, Part1, Par2; you want to send a event to Part2 from a transition in Part1), you can use:
%SEND_EVENT("EventName", CONTEXT_REF(context instance name))%
like:
%SEND_EVENT("CCC", CONTEXT_REF(Part2))%