主要内容

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

systemcomposer.interaction.Message

生命线之间的消息交互

自 R2024a 起

    说明

    Message 对象表示交互中两条生命线之间的通信。在表示交互的序列图上,消息以箭头的形式显示。消息有标签,可以正式或非正式地描述通信的发生。消息相当于架构模型中连接两个组件端口的连接器。

    一个消息标签有一个触发条件 (trigger)、一个可选的保护条件 (guard) 和一个可选的约束条件 (constraint),其形式为 trigger[guard]{constraint}trigger 表示此消息的标识事件。guard 表示确定消息是否发生的附加条件。constraint 是当此消息发生时预期为 true 的表达式。

    • 在信号事件中,触发器遵循以下格式:direction(signal [+|-] value),它指定了带有方向和表达式的触发边沿。方向可以是:

      • 上升 - 边沿表达式从严格低于零上升到等于或大于零的值。

      • 下降 - 边沿表达式从严格高于零开始下降。

      • 交叉 - 上升或下降过零的边沿表达式。

    • 在消息事件中,触发器的格式为 port,指定输入消息端口的名称,代表消息的到达。

    • 消息标签上方括号内的保护条件是一个 MATLAB® 布尔表达式,是确定消息是否发生的附加条件。只有在软件检测到有效触发条件时,才会计算保护条件。在执行过程中,序列图会等待进入下一条消息,直到保护表达式计算结果为 true。

    • 消息标签上大括号中的约束条件是一个 MATLAB 布尔表达式,指定了输入目标生命线的预期值。在执行过程中,对约束条件的计算决定了序列图对该消息显示通过还是失败。

    创建对象

    通过相应 systemcomposer.interaction.Interaction 对象的 RootFragment 属性访问 Message 对象。遍历根片段,检查片段中的 systemcomposer.interaction.MessageEvent 对象。访问消息事件的 Message 属性可查看相应的 Message 对象。

    属性

    全部展开

    消息类型,指定为这些选项之一:

    • 用于信号通信的 "Signal"

    • "Message" 用于 Simulink® 基于消息的通信

    数据类型: string

    消息标签,指定为字符串。

    数据类型: string

    消息的开始,指定为 systemcomposer.interaction.MessageEvent 对象。

    消息结束,指定为 systemcomposer.interaction.MessageEvent 对象。

    指定为 systemcomposer.arch.Connectorsystemcomposer.arch.PhysicalConnector 对象数组的消息所代表的连接器。

    唯一外部标识符,指定为字符向量。外部 ID 在元素的整个生命周期以及所有保留 UUID 的操作中都会被保留。

    数据类型: char

    统一唯一标识符,指定为字符向量

    示例: '91d5de2c-b14c-4c76-a5d6-5dd0037c52df'

    数据类型: char

    对象函数

    move在交互中移动消息
    destroy移除模型元素

    示例

    全部折叠

    您可以使用只读 API 工作流浏览 System Composer™ 中的序列图,并显示每个元素的相关信息。

    打开交通灯示例

    打开交通灯示例架构模型,以便直观地检查序列图并确认程序输出。

    model = systemcomposer.openModel("TLExample");

    要查看与模型关联的序列图,请在 System Composer 工具条上导航至建模 > 序列图

    The press detection sequence diagram in the views gallery of the top model.

    以编程方式浏览序列图

    收集由 interactions 表示的序列图,其中包含模型中元素的特定交互。

    interactions = model.getInteractions;

    对于第一个交互,提取序列图的名称。

    disp("The first sequence diagram is called " + interactions(1).Name + ".")
    The first sequence diagram is called SignalSequence.
    

    在该序列图中,显示每条生命线以及生命线所代表的组件。

    for i = 1:length(interactions(1).Lifelines)
        disp("The " + interactions(1).Lifelines(i).Name + ...
        " lifeline represents the " + ...
        interactions(1).Lifelines(i).RelatedElements.Name + ...
        " component.")
    end
    The source lifeline represents the source component.
    The poller lifeline represents the poller component.
    The lampController lifeline represents the lampController component.
    The ped lamp lifeline represents the ped lamp component.
    

    显示根片段中一条消息的内容。

    disp("The sequence diagram message starting at the " + ...
        interactions(1).RootFragment.Operands.Fragments(1).Name + ...
        " message end is of type " + ...
        string(interactions(1).RootFragment.Operands.Fragments(1).Message.Type) + ...
        " and the message label is " + ...
        interactions(1).RootFragment.Operands.Fragments(1).Message.Condition + ".")
    The sequence diagram message starting at the switchout message end is of type Signal and the message label is rising(sw-1){sw==1}.
    

    使用迭代器实用工具逐步浏览序列图

    使用 Inhibit 实用工具逐步浏览 Iterator 序列图。

    interaction = model.getInteraction('Inhibit');
    interaction.open

    Inhibit sequence diagram from the top model.

    显示交互中的注解。

    disp(interaction.Annotations.Content)
    When inhibit is true, it means pedestrian crossing is not controlled by a walk signal on this intersection.
    

    在提取序列图的属性之前,使用迭代器浏览序列图的所有元素。

    iterator = systemcomposer.interaction.Iterator(interaction.RootFragment);
    next = iterator.next;
    while ~isempty(next)
        disp(class(next))
        next = iterator.next;
    end
    systemcomposer.interaction.RootFragment
    systemcomposer.interaction.Operand
    systemcomposer.interaction.MessageEvent
    systemcomposer.interaction.MessageEvent
    systemcomposer.interaction.MessageEvent
    systemcomposer.interaction.MessageEvent
    systemcomposer.interaction.AltFragment
    systemcomposer.interaction.Operand
    systemcomposer.interaction.MessageEvent
    systemcomposer.interaction.MessageEvent
    systemcomposer.interaction.MessageEvent
    systemcomposer.interaction.MessageEvent
    systemcomposer.interaction.Operand
    systemcomposer.interaction.MessageEvent
    systemcomposer.interaction.MessageEvent
    

    详细信息

    全部展开

    版本历史记录

    在 R2024a 中推出