解决方案
模型参数与VeriStand项目中的其他通道不同,无法使用ChannelReference.value方法写入。相反,您必须打开 ModelManager2会话并使用ModelManager2 API中的方法来设置参数值。请参阅ModelManager2 methods in the NIVeriStand Legacy Python API Refence。
例如,这里有一个Python脚本,可用于设置VeriStand附带的Engine Demo模型的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包含许多用于读取和写入单个或多个参数的不同方法。