This example shows how to configure a pair of Stateflow® charts that communicate by sending messages that carry string data. For more information, see Communicate with Stateflow Charts by Sending Messages.
This
model contains two charts that use C
as the action language. During simulation, the Emitter chart reads an
input string key
from the String Constant block and
sends a message to the Receiver chart. The message data consists of the
input string key
. The Receiver chart compares the
string with a constant keyword and returns an output string that grants or denies access.
The Emitter chart consists of a single state A
.
When the state becomes active, it sets the data for the message M
to the input value key
and sends the message to the
Receiver chart.
This table lists the scope and type for the symbols in the chart.
Symbol | Scope | Type |
---|---|---|
key | Input Data | Inherit: Same as Simulink |
M | Output Message | string |
The chart consists of two states joined by a transition. The input message
M
guards the transition. If there is a message present and
its data value equals the constant string lock
, then the state
activity transitions from Off
to On
. The chart
outputs the string value 'Access Granted'
. If there is no message
present, or if the data value does not equal lock
, the chart does
not take the transition and the output value is 'Access Denied'
.
This table lists the scope and type for the symbols in the chart.
Symbol | Scope | Type |
---|---|---|
M | Input Message | Inherit: Same as Simulink |
lock | Constant Data | string |
sout | Output Data | string |
The constant string lock
contains a secret
password, initially set to 'Open Sesame'
. You can change the
value of lock
in the Initial value field of
the Property Inspector.
During simulation, the model responds to the password that you enter in the String Constant block:
If you enter an incorrect password, such as
"Abracadabra"
, then the model displays the output
string "Access Denied"
.
If you enter the correct password, in this case, "Open
Sesame"
, then the model displays the output string
"Access Granted"
.