主要内容

万博1manbetxMessages Overview

在各种应用程序中,基于消息的通信是必需的,例如控制系统体系结构,其中集中式体系结构被系统的复杂性替换为分布式体系结构。在分布式体系结构中,系统的多个组件通过共享网络进行通信。

A distributed architecture has these three elements:

  • 组件 - 表示具有定义I/O接口的一组功能或算法的设计分区。通常,组件异步生成事件和数据。

  • 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

在建模这样的体系结构时,您通常会建模可明确识别,可重复使用和可部署的组件。为了实现组件之间基于事件的异步通信,请使用消息发送和接收接口。建模中间软件,以促进代表组件连接的网络拓扑,例如基于消息发送和接收组件的数量,例如一对多,多一对一或多一对多的网络。例如,请参阅Build a Shared Communication Channel with Multiple Senders and Receivers

要学习如何建模分布式体系结构,请使用Simulink万博1manbetx®,simevents®, and Stateflow®,请参见下面的插图。该插图包括两个消息发送和两个消息接收组件,这些组件被创建为引用模型。使用Simulink的型号具有发送和接收接口的模型组件万博1manbetx发送收到blocks. 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

让我们首先了解消息阻止的工作方式。要创建使用消息的模型,请使用发送blocks to convert data and send messages and收到块接收并将消息转换为数据。对于一个简单的示例,显示了如何发送收到blocks work, seeAnimate and Understand Sending and Receiving Messages

利用发送收到块以模型消息发送和接收组件的接口。有关显示创建发送和接收接口的基础知识的简单示例,请参见Establish Message Send and Receive Interfaces Between Software Components。要了解如何为同一模型生成代码,请参见生成C ++消息以在Simulink组件之间传达数据万博1manbetx(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模型消息接收到在消息可用性上运行的接口

建模后,为您的发送和接收接口生成代码,并将其连接到中间件或操作系统通信API。对于为顶部模型生成代码的示例,并允许您的应用程序在使用外部消息协议服务的分布式系统中进行通信(例如,DDS,ROS,SONEIP或POSIX消息),请参阅Generate C++ Messages to Communicate Data Between Simulink and an Operating System or Middleware(Embedded Coder)

Simulate Middleware Effects on a Distributed Architecture

利用Queue存储,排序和队列消息的块。这Queueblock 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, see利用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。要查看具有带通道故障和数据包丢失的共享无线渠道的模型,请参见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, seeModel an Ethernet Communication Network with CSMA/CD Protocol

Note

SimEvents blocks do not support code generation.

See Also

||||

相关话题