配置 Python 3.8.0 以在 NI VeriStand 中部署 Engine Demo 脚本

更新 Jan 9, 2025

環境

軟體

  • VeriStand 2021 R2

操作系統

  • Windows

程式語言

  • Python

本文介紹如何設定 Python 3.8.0 環境以及透過網際網路連線到 PC 在 NI VeriStand 中佈署Engine Demo 腳本。 Python for .NET (pythonnet 2.5.2) 是一個Python Package,它能讓 Python 開發工程師能夠與 Windows 上的 .NET 4.0+ CLR 幾乎無縫整合。以 Python 實作的niveristand套件包含一個與 NI VeriStand 系統互動的 API(應用程式介面)。
本文的成果是使用 Python 自動化 NI VeriStand 應用程式。

目標受眾是希望透過將 HIL 系統整合到持續整合工作流程中來實現測試流程自動化的 HIL 系統開發人員。


所需先修知識:

  1. NI VeriStand 2021 R2
  2. Python 腳本

Windows系統中的Python安裝

  1. 下載Python 3.8.0安裝檔。
  2. 執行安裝檔在Windows系統上安裝Python 3.8.0。
  3. 選取  Add Python 3.8.0 to PATH 方塊以將 Python 檔案新增至預設路徑。
  4. 按一下立即安裝開始安裝。
Python設定
  1. 安裝完成後,關閉設定視窗。
2.PNG
  1. <Windows 鍵-R> 開啟執行視窗,然後鍵入cmd開啟命令提示字元視窗
  2. 鍵入命令python -m pip install niveristand以在 Python 中安裝 NI VeriStand API。
  3. 安裝完成後,關閉命令提示字元視窗。


在 NI VeriStand 中執行 Python 腳本以自動化引擎演示

  1. 點擊IDLE(Python 3.8. 64 位元)圖示以開啟Python 3.8.0 shell。
閒置的
  1. 按一下「File」>>「New File」以開啟一個新的 Python 腳本檔案。 4.png
  2. 複製 Engine Demo Basic 腳本 將引擎演示範例新增至新的 Python 腳本檔案。
  3. 按一下「File>> Save」Engine Demo Basic  名稱儲存此腳本 5.png
  4. 進入第63行,將run_engine_demo檔案路徑編輯為Engine Demo Basic.py檔案所儲存的檔案路徑。例如,「 C:\\Users\\XX\\Documents\\VeriStand Projects\\Engine Demo\\Python Scripts」。
12.png
  1. 關閉IDLE(Python 3.8.64 位元)視窗。
  2. 找到 NI VeriStand 2021 R2 捷徑並雙擊啟動 NI VeriStand。
6.PNG
  1. 在登陸頁面上,按一下「Engine Demo」。
7.png
  1. 建立 Engine Demo 專案並將其儲存在預設檔案路徑中。
  2. 按一下「 Idle」(閒置),然後按一下「Deploy」(佈署)來佈署引擎示範 VeriStand 專案(在 Windows 作業系統上執行)。
8.png
  1. 成功佈署 Engine Demo 專案後,驗證VeriStand Engine 是否處於「Connected」狀態。
9.png
  1. 右鍵點選步驟 4 中儲存的 Engine Demo Basic.py 腳本。
  2. 選擇使用 IDLE 編輯>>使用 IDLE 3.8(64 位元)編輯,以編輯模式開啟 Python 腳本。
10.png
  1. 按一下「Run>>Run Module」以執行 Python 腳本。
11.png
 
 

執行上述步驟後,使用者可以觀察到引擎演示基本 Python 腳本中編碼的自動化步驟被執行到
  1. 開啟引擎,在 NI VeriStand 應用程式中將desired_rpm 設定為傳遞值 2500,持續 20 秒。
結果-1.png
  1. 20 秒後在 NI VeriStand 應用程式中關閉引擎。
結果-2.png
  1. Python輸出:
結果-3.PNG