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 containing data. In the receiving chart, a queue receives the message and holds it until the chart can evaluate it.
Messages combine some of the functionality of data and events. Like data, messages can transmit numeric and textual information. Like events, messages can trigger transition and state actions. However:
Messages do not trigger charts to wake up. Instead, messages are queued until the chart wakes up. When the chart wakes up, it can respond to the messages in the queue.
Messages are not lost if the receiver chart cannot respond immediately.
For more information, see View Differences Between Stateflow Messages, Events, and Data.
When a chart transition or state action evaluates a 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 Symbols pane, the Stateflow Editor menu, or the Model Explorer.
In the Modeling tab, under Design Data, select Symbols Pane.
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 pane, right-click the row for the message and select Explore. For more information, see Set Properties for a Message.
In the Stateflow Editor, select the option corresponding to the scope of the message that you want to add.
|Input||In the Modeling tab, under Design Data, select Message Input.|
|Output||In the Modeling tab, under Design Data, select Message Output.|
|Local||In the Modeling tab, under Design Data, select Message.|
In the Message dialog box, specify data properties. For more information, see Set Properties for a Message.
In the Modeling tab, under Design Data, select 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
a receiving 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
A message becomes valid when a chart evaluates or receives it. The message remains valid until:
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
In charts that use C as the action language, messages do not support multiword
fixed-point data or data of type