Acknowledging Receipt of Messages

This example illustrates a common design pattern using message semantics: receiving acknowledgements from one or more charts to which you have sent a message.

Receiving acknowledgement from a single chart

The Stateflow® charts "Sender1" and "Receiver" demonstrate acknowledgement from a single recipient.

The "Sender1" chart sends a message to "Receiver" chart and waits for an acknowledgement message. If this acknowledgement is received within 10 seconds, then "Sender" moves to "Done" state. Otherwise, "Sender1" moves to "TimedOut" state.

The "Receiver" chart receives a message from "Sender" and stays in a "Processing" state for 5 seconds and sends an acknowledgement message back to "Sender". It has an input data "fault_present" which is checked to decide whether to skip sending an acknowledgement.

"Sender2" is a Stateflow® chart that sends messages to "Receiver1" and "Receiver2" charts and waits for acknowledgement messages from both charts by moving into the "WaitForAcknowledgements" state. While in this state, it counts the number of acknowledgements it receives by using the "on MESSAGE" syntax in the state action. If both acknowledgements are received within 15 seconds, then "Sender2" moves to "Done" state. Otherwise, "Sender2" moves to "TimedOut" state.

"Receiver1" and "Receiver2" are Stateflow® charts that receive a message from "Sender2" and stay in a "Processing" state for 5 seconds and sends an acknowledgement message back to "Sender2". It has an input data "fault_present" which is checked to decide whether to skip sending an acknowledgement.

MATLAB and Simulink are registered trademarks of The MathWorks, Inc. Please see www.mathworks.com/trademarks for a list of other trademarks owned by The MathWorks, Inc. Other product or brand names are trademarks or registered trademarks of their respective owners.