Model a Message Receive Interface that Runs on Message Availability

This example shows how to synchronize execution with data availability in message-based systems. We show how to model this behavior using events and actions. This example builds on another example, Establish Message Send and Receive Interfaces Between Software Components, where two software components communicate using messages.

As with the previous example, the code generation process should apply to the Send Component and the Receive Component. The Message Storage models the middleware and data notification events provided by the middleware.

Below is the composition model with a Send Component and a Receive Component created by using two Model blocks. These two Model blocks are connected through a Queue block with message lines.

When a message arrives at the Queue block input port, its entry action is invoked. In the Event action tab, in the Entry field, the block calls the Simulink Function onMessageAvailable() which is modeled as an entry-point function in the ReceiveComponent. See Event Action Languages and Random Number Generation (SimEvents) for more information on Event Actions.

The following picture shows the contents of the ReceiveComponent.

As a result, messages sent from the SendComponent trigger execution within the ReceiveComponent. To observe this behavior, use the Sequence Viewer block.

For example, observe the simulation time 0:

  1. The arrow from the Send block to the Queue block represents that a message is sent with a data value of 0.

  2. The arrow from the Queue block to the Simulink Function block indicates a call to the onMessageAvailable() function.

  3. An arrow from the Queue block illustrates that the message with data value 0 is received by the Receive block within this function call.

  4. The horizontal, dashed arrow from the Simulink Function block to the Queue block indicates the return of function onMessageAvailable().

For more information about the Sequence Viewer block, see Use the Sequence Viewer Block to Visualize Messages, Events, and Entities.

See Also

| | |

Related Topics