To communicate within and between Stateflow® charts in a Simulink® model, use messages. A message is a Stateflow object that communicates data locally or between charts. From a sender chart, you can send or forward a message. In the receiving chart, a queue receives the message and holds it until the chart can evaluate it.
Messages are queued until the chart wakes up. When the chart wakes up, it can respond to the messages in the queue.
Messages do not trigger charts to wake up.
Messages are not lost when the receiver chart cannot immediately respond.
When a chart transition or state action evaluates the message, the chart determines if the queue contains any messages. If it does, the chart removes the message from the queue. The message remains valid until the end of the time step or until the chart forwards or discards it. While the message is valid, other transitions or actions can access the message data and the chart does not remove another message from the queue. The chart destroys all valid messages at the end of the current time step.
You can add messages to a Stateflow chart by using the Chart menu in the Stateflow Editor, through the Symbols window, or through the Model Explorer.
In the Stateflow Editor, select the menu option corresponding to the scope of the message that you want to add.
|Input||Chart > Add Inputs & Outputs > Message Input From Simulink|
|Output||Chart > Add Inputs & Outputs > Message Output To Simulink|
|Local||Chart > Add Other Elements > Local Message|
In the Message dialog box, specify data properties. For more information, see Set Properties for a Message.
To open the Symbols window, select View > Symbols.
Click the Create Message icon .
In the row for the new message, under TYPE, click the icon and choose:
Edit the name of the message.
For input and output messages, click the PORT field and choose a port number.
To specify properties for the message, open the Property Inspector. In the Symbols window, right-click the row for the message and select Explore. For more information, see Set Properties for a Message.
In the Stateflow Editor, select View > Model Explorer.
In the Model Hierarchy pane, select the object in the Stateflow hierarchy where you want to make the new message visible. The object that you select becomes the parent of the new message.
In the Model Explorer menu, select Add > Message. The new message with a default definition appears in the Contents pane of the Model Explorer.
In the Message pane, specify the properties of the message. For more information, see Set Properties for a Message.
A Stateflow message has a finite lifetime. The lifetime begins when you send a message to
an input or local queue with the
send operator. The message remains in
the queue until a transition or state
on action evaluates it or the chart
receives it by using the
A message becomes valid when a chart evaluates or receives it. The message remains valid until:
The end of the current time step, when the chart destroys any remaining valid messages.
The chart forwards the message to another queue. The message continues its lifetime in the receiving queue.
The chart discards the message.
While a message is valid, other transitions and actions can evaluate the
message and access its data. To check if a message is valid, use the
To view the interchange of messages during simulation, add a Sequence Viewer block to your Simulink model. The Sequence Viewer block displays:
For more information, see Use the Sequence Viewer Block to Visualize Messages, Events, and Entities.
You cannot use messages in:
Breakpoint condition expressions
Model reference inputs and outputs
Messages do not support fixed-point data.