Main Content

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 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 theEvent actiontab, in theEntryfield, the block calls the Simulink FunctiononMessageAvailable(). SeeEvent Action Languages and Random Number Generation(SimEvents)for more information on Event Actions.

When the 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 theSequence Viewerblock.

For example, observe the simulation time0:

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

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

  3. An arrow from the Queue block illustrates that the message with data value0是接收d 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 functiononMessageAvailable().

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

See Also

|||

Related Topics