Holarch
課程章節

培訓 · 第 9 單元:SysML v2 基礎 · 第 9.2 章,共 8 章

9.2 埠與介面 3:44

定義埠與介面、在文字中連接零件,並在檢視中繪製介面。

展示 Holarch 2.22。

您將學到

  • 定義具有方向性屬性的埠,並以 `~` 使其共軛
  • 定義兩端以埠為類型的介面
  • 以介面用法連接零件,並將邊界埠繫結到內部零件的埠
  • 建立 Interconnection View,並在兩個埠之間繪製介面

在 Holarch 中定義 SysML v2 埠與介面,依循 SysML v2 教學課程 Ports and Interfaces,以一個小型 Hybrid Car 專案進行:具有方向的埠定義、共軛埠、具有兩端的介面定義、其零件以介面與繫結連接的動力系統、它的 Interconnection View,以及在檢視中繪製、由 Holarch 寫入文字的介面。SysML 是 Object Management Group, Inc. 的註冊商標。

專案檔案

  • 完成的專案 (.holarch.json;管理專案 → 專案檔案 ▾ → 匯入專案 (.json)…)

影片從 holarch.app 播放;請參閱隱私權政策。

練習

在 Holarch 中於 Hybrid Car 示範專案(SysML v2)上親自操作。

  1. 開啟您的 Hybrid Car 示範專案(如有需要請建立:管理專案 → 專案檔案 ▾ → 新增示範專案 → Hybrid Car (SysML v2)),開啟模型 → 編輯器以及套件 Vehicles。
  2. 在 interface def HighVoltageBus 下方新增 interface def ControlLink { end commander : ~ControlPort; end unit : ControlPort; }。
  3. 在 part def Powertrain 中,將 connect controller.engineCtl to engine.ecu; 取代為 interface engineControl : ControlLink connect controller.engineCtl to engine.ecu;,並在 part battery : Battery; 之後新增 part auxBattery : Battery;。
  4. 開啟架構 → Interconnection View以及檢視 powertrainConnections。從 auxBattery 的埠 powerOut 的控點拖曳到馬達的埠 powerIn,然後選擇 Interface : HighVoltageBus。
  5. 選取新的線條,並在屬性面板中將其名稱輸入為 auxBus。然後開啟模型 → 編輯器,找到 Holarch 在 Powertrain 中寫入的那一行。

當 Powertrain 包含 interface engineControl : ControlLink … 以及來自檢視的 auxBus 介面,且編輯器下方的狀態回報沒有問題時,即完成。

自我檢查

  1. 引擎有 port fuelIn : ~FuelPort;。波浪號改變了什麼?
  2. bind output = transmission.output; 與 interface fuel : FuelLine connect tank.fuelOut to engine.fuelIn; 有什麼不同?
  3. 當您從電池的 powerOut 拖曳到馬達的 powerIn 時,為什麼檢視會提供 Interface : HighVoltageBus?
顯示答案
  1. 引擎有 port fuelIn : ~FuelPort;。波浪號改變了什麼?

    它使埠共軛:引擎的埠具有與 FuelPort 相同的特徵,但方向相反,因此 FuelPort 的 out attribute flowRate 會以輸入的形式抵達引擎。

  2. bind output = transmission.output; 與 interface fuel : FuelLine connect tank.fuelOut to engine.fuelIn; 有什麼不同?

    繫結表示兩個特徵是同一個:動力系統的邊界埠就是變速箱的輸出。介面用法則連接兩個不同的埠,而其介面定義說明它的兩端接受哪些埠。

  3. 當您從電池的 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.