Main Content

Observe Messages

Simulink® uses messages to communicate between model components. When your model includes one or more message signals, you can create an Observer model to observe the message data. When you create the Observer model, it creates metadata associated with the message. You can test the message semantics and verify the message properties by using both the message data and metadata.

Message Bus Elements

When you create an Observer for a message signal, the Observer model automatically includes an Observer Port block and a Bus Selector block. The bus has two elements:

  • OrigPayload — The message data being observed.

  • Metadata with these elements:

    • — ID of message being observed, returned as an int32 integer.

    • sltestEventMetadata.Message.order — Order of message action in the simulation, returned as an int32 integer.

    • sltestEventMetadata.Message.eventType — The event type, returned as slTestEventType object. Valid values are MessageArrival, MessageDeparture, MessageDrop, and Invalid.

    • sltestEventMetadata.Message.time — Simulation time when the message was sent, received, or dropped, returned as a double.

Add a Message Observer

To add an observer for messages:

  1. In the model that has one or more blocks that output messages, right-click the output message signal to observe.


    Messages from blocks with asynchronous sample times are supported only for SimEvents® blocks that generate their own sample times.

  2. Select Observers > Observe selected signals > New Observer to create an Observer model for the message signal. An Observer Reference block is added to the main model and an Observer model is created.

    The new Observer model contains an Observer Port block and Bus Selector block. The Bus Selector block has two outputs, OrigPayload and Metadata. You can use the default settings in the Observer Port block to observe the outputs from the bus.

    Observer Port block and Bus Selector block and outputs in Observer model

  3. Connect the outputs from the bus to a block, such as a Test Assessment block or a Stateflow® chart, to specify the logic to analyze or verify the message data or metadata.

Observe a Message Signal

Open a model that has a block with message output. For this example, open the Overflow model, which contains an Observer model.


In this model, the Sine Wave2 block sends data every 0.1 seconds, but the Receive2 block receives data only every 0.5 seconds. Because the Queue2 FIFO block holds a maximum of three messages, an overflow occurs and some messages are dropped from the queue.

The Observer model was set up by selecting the message signals, right-clicking on one of them, and selecting Observers > Observe selected signals > New Observer. The Observer block, which is an Observer Reference block, was automatically added to the main model.

Main model with sine wave block connected to send block. Send block is connected to FIFO queue, which is connected to receive block

Open the Observer model by double-clicking the Observer block in the main model, or by using this command:


The Observer model contains two Observer Port blocks, Send and Receive, which correspond to the signals selected in the main model. Each of these blocks is connected to a Bus Selector block with two outputs. The OrigPayload output is the message data being observed and the Metadata output contains the message ID, order of the message in the simulation, the message event type, and the simulation time of the message.

Observer model with send and receive blocks connected to bus selector.

The bus signal outputs connect to two Stateflow charts, which analyze the message data.

The chart for the messages from the Receive Observer port block contains logic that verifies that the message data and metadata are not corrupted due to messages being dropped because of Queue block overflows.

The chart logic verifies that:

  • Sine wave data is in the expected range, which is between 0 and 1

  • The order of the messages and simulation time increments and that each order value is unique

  • Message event type is a valid type

Stateflow chart with message logic

See Also


Related Topics