主要内容

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

addOperand

在片段中添加操作数

自 R2024b 起

    说明

    operand = addOperand(fragment) 将操作数添加到指定的 fragment 中。

    示例

    operand = addOperand(fragment,guard) 将带有 guard 的操作数添加到指定的 fragment 中。

    示例

    operand = addOperand(___,After=existingOperand) 在指定的 fragmentexistingOperand 之后添加一个带有 guard 的操作数。

    示例

    全部折叠

    以编程方式创建一个序列图,描述行人在有交通信号灯的十字路口过马路的情景。

    要了解有关序列图的更多信息,请参阅以交互方式编写序列图

    打开交通灯示例

    加载 TLExample 架构模型。

    model = systemcomposer.openModel('TLExample');

    TLExample architecture model with various components.

    创建一个名为 'InhibitCopy' 的新序列图。

    diagram = model.addInteraction('InhibitCopy');

    添加生命线

    为架构中的每个组件添加生命线。

    sourceLifeline = diagram.addLifeline('TLExample/source');
    pollerLifeline = diagram.addLifeline('TLExample/poller');
    switchLifeline = diagram.addLifeline('TLExample/switch');
    lampLifeline = diagram.addLifeline('TLExample/lampController');
    controllerLifeline = diagram.addLifeline('TLExample/controller');

    获取交互的根片段和根操作数。

    rootFragment = diagram.RootFragment;
    rootOperand = rootFragment.Operands(1);

    添加消息和片段

    向根操作数添加两条消息。

    sourceToPollerMsg = rootOperand.addMessage(sourceLifeline, "switchout", pollerLifeline, "sw", "rising(sw-1){sw==1}");
    pollerToSwitchMsg = rootOperand.addMessage(pollerLifeline, "switchEvent", switchLifeline, "switchEvent", "switchEvent{switchEvent==1}");

    向根操作数添加一个条件片段。

    altFrag = rootOperand.addFragment('Alt');

    为条件片段的每个操作数指定保护表达式。

    op1 = altFrag.Operands(1);
    op1.Guard = "switch/inhibit==0";
    op2 = altFrag.addOperand("switch/inhibit==1");

    向条件片段的第一个操作数添加两条消息。

    switchToLampControllerMsg1 = op1.addMessage(switchLifeline, "lampColor", lampLifeline, "switchPed", "switchPed{switchPed==1}");
    switchToControllerMsg = op1.addMessage(switchLifeline, "switchPush", controllerLifeline, "pedRequest", "pedRequest");

    在条件片段的第二个操作数中添加一条消息。

    switchToLampControllerMsg2 = op2.addMessage(switchLifeline, "lampColor", lampLifeline, "switchPed", "switchPed{switchPed==2}");

    添加持续时间约束

    在条件片段第一个操作数中的两个消息之间添加一个持续时间约束。

    startEvent = switchToLampControllerMsg1.End;
    endEvent = switchToControllerMsg.End;
    expression = "t > 12msec";
    durationConstraint = diagram.addDurationConstraint(startEvent, endEvent, expression);

    打开序列图

    打开新创建的序列图。

    open(diagram);

    Newly created sequence diagram called 'InhibitCopy'.

    输入参数

    全部折叠

    保护条件,指定为字符向量或字符串。

    示例: "switch/inhibit==0"

    数据类型: char | string

    当前片段中的现有操作数,指定为 systemcomposer.interaction.Operand 对象。

    输出参量

    全部折叠

    添加的操作数,以 systemcomposer.interaction.Operand 对象形式返回。

    详细信息

    全部折叠

    版本历史记录

    在 R2024b 中推出