|
1、Canoe获取启动Canoe,停止Canoe,获取系统变量,更改系统变量,获取信号值Canoe工程如下2、Python_canoe_start_and_stop_variables_and_signals_read_and_write.py代码如下#--------------------------------------------------------------------------#Standardlibraryimportsimportosimportsysimportsubprocessimporttimeimportmsvcrtfromwin32com.clientimport*fromwin32com.client.connectimport*#VectorCanoeClassclassCANoe:def__init__(self,visible=True):self.application=Noneself.application=DispatchEx("CANoe.Application")#self.application.Versible=visibleself.ver=self.application.Versionprint('LoadedCANoeversion',self.ver.major,'.',self.ver.minor,'.',self.ver.Build,'...')#,sep,''self.Measurement=self.application.Measurement.Runningdefopen_cfg(self,cfgname):#openCANoesimulationcfgname=os.path.abspath(cfgname)if(self.application!=None):#checkforvalidfileanditis*.cfgfileifos.path.isfile(cfgname)and(os.path.splitext(cfgname)[1]==".cfg"):self.application.Open(cfgname)print("opening..."+cfgname)else:raiseRuntimeError("Can'tfindCANoecfgfile")else:raiseRuntimeError("CANoeApplicationismissing,unabletoopensimulation")defclose_cfg(self):#closeCANoesimulationif(self.application!=None):print("closecfg...")#self.stop_Measurement()self.application.Quit()self.application=Nonedefstart_Measurement(self):retry=0retry_counter=5#trytoestablishmeasurementwithin5stimeoutwhilenotself.application.Measurement.Runningand(retry")defOnStop(self,reason):self.started=Falseself.stopped=Trueprint("")classCanoeMeasurementEvents(object):"""HandlerforCANoemeasurementevents"""defOnStart(self):CanoeSync.Started=TrueCanoeSync.Stopped=Falseprint("")defOnStop(self):CanoeSync.Started=FalseCanoeSync.Stopped=Trueprint("")defmain():Tester=CanoeSync()Tester.Load(r'../Pressure_measurement_collection/Pressure_measurement_collection/CANoecfg/Pressure_measurement_collection.cfg')Tester.LoadTestSetup("Pressure_measurement_collection.tse")Tester.Start()Tester.RunTestModules()Tester.Stop()if__name__=="__main__":main()文章借鉴:Python调用CANoe(1)(启动与停止,变量和信号读写)-CSDN博客
|
|