This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Send Messages with String Data

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.

Emitter Chart

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.

SymbolScopeType
keyInput DataInherit: Same as Simulink
MOutput Messagestring

Receiver Chart

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.

SymbolScopeType
MInput MessageInherit: Same as Simulink
lockConstant Datastring
soutOutput Datastring

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.

View Simulation Results

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".

See Also

Related Topics