MATLAB Answers

Stateflow messages and events

53 views (last 30 days)
ANDREA DI MARTINO
ANDREA DI MARTINO on 24 Mar 2020 at 14:26
Commented: ANDREA DI MARTINO on 30 Mar 2020 at 15:45
I'm using stateflow for a state machine. I know that in state flow there are messages and events. With the first one I can associate a data but I can send the message only with the send(M) so I can't specify which state will receive the message M. Instead, if I use an event I can send this to a specific state with send(event,state) but I can't associate a data to the event. I need a kind of fusion between event and messages. I need to send a data in a particular state of the chart. I won't create a lot of messages like M1, M2 and so on. I ask this because i need that a message from a state 1 must be different form a message from state 2 but they must have the same name. So if the message has value 1 it comes from the state 1 and so on. Sorry for my bad english

  0 Comments

Sign in to comment.

Answers (2)

Harsha Priya Daggubati
Harsha Priya Daggubati on 27 Mar 2020 at 7:49
Edited: Harsha Priya Daggubati on 27 Mar 2020 at 7:50
Hi,
As per my understanding, you can attach a key (which can be distinct based on sender) to the message you intend to send, and can check for it at the receiver end. This might help you:

  1 Comment

ANDREA DI MARTINO
ANDREA DI MARTINO on 27 Mar 2020 at 8:31
Thank you for the reply. The problem is that i must use messages inside a stateflow chart. I have a big stateflow chart with 3 parallel states that must comunicate with messages. I havo no reciever or sender because every state is a sender or receive. The problem is this. I send a message from a state S1 like M.data =1 and send(M). The problem is that the state S1 recieve the same message that he sent. In the picture you can see that i have 3 parallel states that must comunicate between them to use a mutual exlusive resource using the two phase commit protocol. So i need to send 3/4 messages to make the access to the resource exclusive.

Sign in to comment.


Harsha Priya Daggubati
Harsha Priya Daggubati on 27 Mar 2020 at 9:07
Edited: Harsha Priya Daggubati on 27 Mar 2020 at 9:14
By the following statement, 'I send a message from a state S1 like M.data =1 and send(M). The problem is that the state S1 recieve the same message that he sent', do you mean that the message is being received by the same state from which it is sent? But it is expected as 'send' broadcasts the message.

  4 Comments

Show 1 older comment
Harsha Priya Daggubati
Harsha Priya Daggubati on 27 Mar 2020 at 10:06
I guess as of now, you couldnot send any data with event. You only have to use message for sending data and it cannot be directed to a particular state as of now.
ANDREA DI MARTINO
ANDREA DI MARTINO on 27 Mar 2020 at 10:33
Ok but i can't use send(M,S2) if M is a message. I obtain this:
Messages do not support directed send() syntax. Please use state local messages in order to direct a message to a state. Transition in Chart 'buonastrada/SmartFactory': {send(prepare,R2)}
In model explorer prepare is a local message of the big statechart that includes all other states
ANDREA DI MARTINO
ANDREA DI MARTINO on 30 Mar 2020 at 15:45
Harsha Priya Daggubati, can you help me? Did you read my answer?

Sign in to comment.

Sign in to answer this question.

Tags

Products


Release

R2019b