解決方案
模型參數與 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 包含許多不同的方法來讀取和寫入單一或多個參數。