课程章节
培训 · 课程 9. SysML v2 基础 · 第 9.2 章,共 8 章
9.2 端口和接口 3:44
定义端口和接口,在文本中连接部件,并在视图中绘制接口。
演示 Holarch 2.22。
您将学到
- 定义带有方向属性的端口,并用 `~` 对其进行共轭
- 定义两端以端口为类型的接口
- 用接口用法连接部件,并将边界端口绑定到内部部件的端口
- 创建 Interconnection View,并在两个端口之间绘制接口
在 Holarch 中定义 SysML v2 端口和接口,基于一个小型 Hybrid Car 项目,依照 SysML v2 教程“端口和接口”:带方向的端口定义、共轭端口、有两端的接口定义、各部件通过接口和绑定相连的动力总成、它的 Interconnection View,以及在视图中绘制并由 Holarch 写入文本的接口。SysML 是 Object Management Group, Inc. 的注册商标。
练习
在 Holarch 中基于 Hybrid Car 演示项目 (SysML v2) 亲自完成此操作。
- 打开您的 Hybrid Car 演示项目(如有需要,请创建:管理项目 → 项目文件 ▾ → 新建演示项目 → Hybrid Car (SysML v2)),打开 模型 → 编辑器 和包
Vehicles。 - 在
interface def HighVoltageBus下方添加interface def ControlLink { end commander : ~ControlPort; end unit : ControlPort; }。 - 在
part def Powertrain中,将connect controller.engineCtl to engine.ecu;替换为interface engineControl : ControlLink connect controller.engineCtl to engine.ecu;,并在part battery : Battery;之后添加part auxBattery : Battery;。 - 打开 架构 → Interconnection Views 和视图
powertrainConnections。从auxBattery的端口powerOut的手柄拖到电机的端口powerIn,然后选择 Interface : HighVoltageBus。 - 选择新连线,在属性面板中将其 名称 设为
auxBus。然后打开 模型 → 编辑器,找到 Holarch 在Powertrain中写入的那一行。
当 Powertrain 包含 interface engineControl : ControlLink … 以及来自视图的 auxBus 接口,且编辑器下方的状态报告没有问题时,即完成练习。
自测
- 发动机有
port fuelIn : ~FuelPort;。波浪号改变了什么? bind output = transmission.output;与interface fuel : FuelLine connect tank.fuelOut to engine.fuelIn;有什么区别?- 为什么从电池的
powerOut拖到电机的powerIn时,视图会提供 Interface : HighVoltageBus?
显示答案
发动机有
port fuelIn : ~FuelPort;。波浪号改变了什么?它对端口进行共轭:发动机的端口具有与 FuelPort 相同的特征,但方向相反,因此 FuelPort 的
out attribute flowRate到达发动机时成为输入。bind output = transmission.output;与interface fuel : FuelLine connect tank.fuelOut to engine.fuelIn;有什么区别?绑定表示两个特征是同一个:动力总成的边界端口就是变速器的输出。接口用法连接两个不同的端口,其接口定义说明其两端接受哪些端口。
为什么从电池的
powerOut拖到电机的powerIn时,视图会提供 Interface : HighVoltageBus?Holarch 提供两端都适合这两个端口的接口定义。HighVoltageBus 的两端为
source : PowerPort和load : ~PowerPort,与这两个端口匹配。
延伸阅读
文字稿
显示文字稿 (旁白和屏幕内容)
Introduction
Chapter two: ports and interfaces. A port is where a part meets the world outside it. An interface says which ports may connect.
In this chapter you define a port and an interface, connect parts in a powertrain, and draw an interface in a view.
Start the tutorial
Start the tutorial Ports and Interfaces from Project Files, Start a Tutorial. Its starter project holds the car's components with their torque and power ports, two interface definitions, and nothing yet for fuel.
On screen: Project Files ▾ → Start a Tutorial… → SysML v2: Ports and Interfaces → Start.
Ports
Above the torque port, define the fuel port. A port definition lists what crosses the port. Out means the flow rate leaves the part that owns the port.
On screen: Below FuelKind; type port def FuelPort.
The tank owns a fuel port. The engine takes fuel in, so its port is conjugated with a tilde: the same features, with in and out reversed.
On screen: FuelTank: port fuelOut : FuelPort; Engine: port fuelIn : ~FuelPort;
Interfaces
An interface definition says which ports may connect. Below the high voltage bus, define the fuel line, with a supply end and a conjugated consumer end.
On screen: Below HighVoltageBus; type interface def FuelLine.
Connect the parts
Now the powertrain: a part definition made of parts. Its own output port is bound to the transmission's output, so the two are one and the same.
On screen: After Transmission; type part def Powertrain with five parts, a port and bind.
Connect the tank to the engine with a fuel line. A dotted name reaches into a part: from the tank's fuel out, to the engine's fuel in.
On screen: In Powertrain after part transmission: interface fuel : FuelLine connect tank.fuelOut to engine.fuelIn;
The engine and the motor both drive the transmission, through a shaft each.
On screen: Two shaft interfaces.
The status under the editor says the text is applied, with no problems.
On screen: Applied, No problems.
The Interconnection View
Now see the powertrain as a view. Open Architecture, then Interconnection Views, and click New Diagram. Keep Interconnection View, choose the powertrain under Shows, and click Create.
On screen: Architecture → Interconnection Views → + New Diagram; Shows: Vehicles::Powertrain; Create.
The parts sit inside the frame with their ports on their sides. Each line is an interface from the text, and the output port on the frame is bound to the transmission.
On screen: The view.
Draw an interface
The battery does not feed the motor yet. Drag from the battery's power out port to the motor's power in. Holarch offers what fits both ports: choose Interface, High Voltage Bus.
On screen: Select battery.powerOut; drag its handle to motor.powerIn → Interface : HighVoltageBus.
Select the new line, and name it H V Bus in the inspector.
On screen: Click the new line; inspector Name: hvBus.
Close the inspector and open the text again. Holarch wrote the interface into the powertrain, with its name, its type and both ends.
On screen: Inspector ×; Model → Editor: the interface hvBus line in Powertrain.
Recap
Every step is ticked off. Click Mark as Done.
On screen: Step panel → Mark as Done.
Let's recap. You defined a port with a direction, conjugated it for the engine, defined an interface with two ends, connected the powertrain's parts in text, and drew an interface that Holarch wrote back into the text.
Next, actions and flows describe what the car does.