simulink messages 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.
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, see .
to learn how to model a distributed architecture, using simulink®, simevents®, and stateflow®, see the illustration below. the illustration includes two message sending and three message receiving components that are created as referenced models. you can model components with send and receive interfaces using simulink and blocks. if your send and receive interfaces involve states or require decision logic, use a stateflow chart. you can also model event-driven or message triggered receive interfaces using .
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, use send blocks to convert data and send messages and receive blocks to receive and convert messages to data. for a simple example that shows how send and receive blocks work, see animate and understand sending and receiving messages.
use send and receive blocks to model message send and receive interfaces for your components. for a simple example that shows the basics of creating send and receive interfaces, see . to learn how to generate code for the same model, see (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, see .
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), see (embedded coder).
model event-driven receive interfaces
use block to configure your subsystem to be triggered by messages and to respond to events.
when you use message triggered subsystem block in scheduled mode, the execution order of the subsystem can be scheduled as aperiodic partitions using the schedule editor to model an asynchronous behavior. the subsystems pull and process the data based on a schedule instead of periodic execution. for an example, see .
simulate middleware effects on a distributed architecture
use blocks to store, sort and queue messages. the queue block allows you to specify message storage capacity and the overwriting and sorting policies for message transitions. for a simple example that shows how a queue block works, see .
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, see (simevents).
for basic communication patterns that can be modeled by simevents, see modeling 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, see . to see a model with shared wireless channel with channel failure and packet loss, see model 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, see .
note
simevents blocks do not support code generation.
see also
| | | |
related topics
- (embedded coder)
- (embedded coder)
- (embedded coder)
- (embedded coder)
- (simevents)