主要内容

本页采用了机器翻译。点击此处可查看最新英文版本。

使用 Adapter 模块合并消息连接

此示例展示了如何使用 Merge 模块在软件架构中的软件组件之间路由消息。Merge 模块是一个预配置的 Adapter 模块,用于合并消息和信号连接。

打开模型。

systemcomposer.openModel('MergeMessagesfromSoftwareComponents');

在此模型中,基于消息的通信在三个软件组件之间构建:两个发送组件 Component1Component2 创建消息并将其发送给接收组件 Component3

Outbound connections from Component1 and Component2 merge using an Adapter block configured as a Merge block to connect to Component3.

FIFO 队列用作组件之间的消息缓冲区。

Component1 链接到 Simulink® 行为模型 swMergeSend1,在每个 0.1 的采样时间生成值为 1 的消息。

Constant block with value 1 creates a signal that is converted to a message via a Send block to output a message.

Component2 链接到 Simulink 行为模型 swMergeSend2,在每个 0.3 的采样时间生成值为 2 的消息。

Constant block with value 2 creates a signal that is converted to a message via a Send block to output a message.

Component3 链接到 Simulink 行为模型 swMergeReceive,负责接收消息并将其转换为信号。输入总线元素端口模块用于将组件外的队列配置为容量为 100 的 FIFO 队列。

In Bus Element port block with a message is converted to a signal via a Receive block to output a signal to the Scope block.

仿真模型。请注意,swMergeReceive 中的 Scope 模块显示了从两个组件接收到的值。

The Scope block displays the message values received from both Send components.

另请参阅

| |

主题