Main Content

金宝appMessages Overview

Message-based communication is necessary in various applications, such as control system architectures in which centralized architectures are replaced with distributed architectures due to the complexity of the systems. In a distributed architecture, multiple components of the system communicate via a shared network.

A distributed architecture has these three elements:

  • Component — Represents partitions of a design that performs a set of functionalities or algorithms with defined I/O interfaces. Generally, components generate events and data asynchronously.

  • Interface — Provides a shared boundary through which components of the system communicate. To provide asynchronous communication, messages are useful modeling artifacts that combine events with related data.

  • Middleware — Provides the services needed by the components to support asynchronous communication across the shared network.

Below is an illustration that shows the composition of a distributed architecture and its elements.

Message based modeling framework

When modeling such an architecture, you typically model components that are clearly identifiable, reusable, and deployable. To achieve asynchronous event-based communication between components, use message send and receive interfaces. Model the middleware to facilitate the network topology that represents the connectivity of components, such as one-to-many, many-to-one, or many-to-many based on the number of message sending and receiving components. For an example, seeBuild a Shared Communication Channel with Multiple Senders and Receivers.

To learn how to model a distributed architecture, using Simulink®, SimEvents®, and Stateflow®, see the illustration below. The illustration includes two message sending and two message receiving components that are created as referenced models. Model components with send and receive interfaces using SimulinkSendandReceiveblocks. If your send and receive interfaces involve states or require decision logic, use a Stateflow chart.

Message based modeling using Simulink, Stateflow, and SimEvents

After you model your components and interfaces:

  • Simulate the behavior of your distributed architecture by modeling the middleware using SimEvents. Using the blocks from the SimEvents library, you can model custom routing and communication patterns, such as merging, delaying, distributing, and broadcasting messages, and investigate the effects of middleware on your communication network.

  • Generate code for your components, including the interface, and connect to your middleware or an operating system communication API.

Model Message Send and Receive Interfaces and Generate Code

Let us start by understanding how message blocks work. To create a model that uses messages, useSendblocks to convert data and send messages andReceiveblocks to receive and convert messages to data. For a simple example that shows howSendandReceiveblocks work, seeAnimate and Understand Sending and Receiving Messages.

UseSendandReceiveblocks to model message send and receive interfaces for your components. For a simple example that shows the basics of creating send and receive interfaces, seeEstablish Message Send and Receive Interfaces Between Software Components. To learn how to generate code for the same model, seeGenerate C++ Messages to Communicate Between Simulink Components(Embedded Coder).

You can further modify send and receive interfaces for custom behavior. For example, you can synchronize when a receive interface executes to when data is available. For more information, seeModel a Message Receive Interface that Runs on Message Availability.

After modeling, generate code for your send and receive interfaces and connect them to the middleware or an operating system communication API. For an example that generates code for a top model and allows your application to communicate in a distributed system that uses an external message protocol service (for example, DDS, ROS, SOMEIP, or POSIX messages), seeGenerate C++ Messages to Communicate Between Simulink and an Operating System or Middleware(Embedded Coder).

Simulate Middleware Effects on a Distributed Architecture

UseQueueblocks to store, sort and queue messages. TheQueueblock allows you to specify message storage capacity and the overwriting and sorting policies for message transitions. For a simple example that shows how aQueueblock works, seeUse a Queue Block to Manage Messages.

You can also use SimEvents to model and simulate middleware effects on your communication network. Use the blocks provided by the SimEvents library to model message routing, peer-to-peer communication, wireless communication, packet loss, and channel delays. For more information about SimEvents, seeDiscrete-Event Simulation in Simulink Models(SimEvents).

For basic communication patterns that can be modeled by SimEvents, seeModeling Message Communication Patterns with SimEvents. You can use combinations of these patterns to create more complex communication behavior. For an example of a system with multiple message sending and receiving components and an ideal shared channel with delay, seeBuild a Shared Communication Channel with Multiple Senders and Receivers. To see a model with shared wireless channel with channel failure and packet loss, seeModel Wireless Message Communication with Packet Loss and Channel Failure.

To see an example that shows how to model more complex network behavior, such as an Ethernet communication network with CSMA/CD protocol, seeModel an Ethernet Communication Network with CSMA/CD Protocol.

Note

SimEvents blocks do not support code generation.

See Also

||||

Related Topics