Main Content

Connect Message Receive Interface with Simulink Functions

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 SendComponent and the ReceiveComponent. The Message Storage models the middleware and data notification events provided by the middleware.

Below is the composition model with a SendComponent and a ReceiveComponent 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, its arrival is communicated to the ReceiveComponent by using Queue entry event action. This activates the Simulink Function block inside the ReceiveComponent to accept a new message for processing.

To achieve this behavior, in the Queue block, in the Event action tab, in the Entry field, the block calls the Simulink Function onMessageAvailable(). See Event Action Languages and Random Number Generation (SimEvents) for more information on Event Actions.

When the Simulink Function block is activated, it accepts a message and converts it to a signal.

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 to Visualize Messages, Events, and Entities.

See Also

| | |

Related Topics