用 VeriStand Python API 時出現通道沒有寫入存取權限錯誤 Error -307665

更新 Jan 9, 2025

產品資訊

軟體

  • VeriStand

程式語言

  • Python

問題敘述

我使用 VeriStand Python API 在佈署的 VeriStand 專案中設定通道值,我能夠為專案中的大多數通道建立Channel Reference  (通道引用),並寫入物件的 value 屬性以設定通道值,如API 參考範例所示。但是當我使用此方法寫入模型的參數時,出現以下錯誤:

The call into the C# API failed with error code -307665. Message: NI VeriStand: Channel does not have write access. 

解決方案

模型參數與 VeriStand 專案中的其他頻道不同,不能使用ChannelReference.value方法寫入。相反地,您必須開啟 ModelManager2 Session 並使用 ModelManager2 API 中的方法設定參數值。請參閱NIVeriStand Legacy Python API 參考 中的 ModelManager2 方法

例如,以下是一個 Python 腳本,可用來設定 VeriStand 隨附的引擎示範模型的 Idle_Speed_RPM 參數。在執行此程式碼之前,請在 VeriStand 中開啟 Engine Demo 範例專案並佈署它。

from niveristand.legacy import NIVeriStand

def set_parameter_value():
    
    # Open a ModelManager2 reference using "localhost" as the gateway address.
    modelRef = NIVeriStand.ModelManager2("localhost")
	
    #Here we use the the SetSingleParameterValue(target, name, value) method from the ModelManager2 API. Target is the name of the controller where the model is running. Name is the name or expression of the model parameter you wish to set. 
    modelRef.SetSingleParameterValue("Controller","Idle_Speed_RPM", 1500)

if __name__ == '__main__':
    set_parameter_value()

ModelManager2 包含許多不同的方法來讀取和寫入單一或多個參數。

相關資訊

Model Manager  (模型管理器) 是一個非同步程序,可讓您批量讀取和寫入模型參數,這樣就不會影響執行模型的迴圈的效能。

有關與參數交互的方式的更多詳細資訊,請參閱設定模型參數