python通过win32com库调用UDE工具来做开发调试实现自动化源码,以及UDE的知识点介绍
在 车载软件开发(Automotive SW Development) 中,UDE 是一个非常重要的调试工具环境。
我们来系统讲一下——
🚗 一、UDE 是什么?
UDE 全称是:
Universal Debug Engine
它是由 PLS (Programmierbare Logik & Systeme GmbH) 公司开发的一款 通用调试环境,
用于 车载 ECU(Electronic Control Unit)开发、调试和测试。
👉 简单来说:
UDE = ECU 调试器 + Trace 分析工具 + 硬件仿真支持环境
🧩 二、UDE 的核心功能
功能类别 | 说明 |
---|---|
🧠 程序调试(Debugging) | 支持单步执行、断点、变量监视、寄存器查看、内存读写等(像 Visual Studio 调试器,但用于 ECU) |
🧩 多核调试(Multicore Debugging) | 支持多核 MCU(如 Infineon AURIX、NXP MPC、Renesas RH850 等)同步调试 |
🔍 Trace 跟踪 | 可以用 Trace32 或 On-Chip Trace(例如 DAP / ETM)采集代码执行轨迹、时间分析 |
⚙️ 集成测量与标定(Measurement & Calibration) | 可以与 INCA、CANape 等标定工具配合(通过 XCP / DAP 接口) |
🧩 脚本与自动化 | UDE 提供 Python / COM / UDE API,可以实现自动化调试、下载、测试等流程 |
🧱 闪存下载(Flash Programming) | 支持通过调试接口(JTAG、DAP、Nexus 等)烧录 ECU 固件 |
⚙️ 三、UDE 通常配合哪些硬件和软件使用
类别 | 示例 |
---|---|
🔌 调试硬件接口 | PLS UAD2 / UAD3 / UAD3+ / UAD3+Next |
🧠 支持 MCU | Infineon AURIX (TC2xx / TC3xx)、NXP MPC5744P、Renesas RH850 等 |
🧰 集成工具链 | 通常与编译器(如 GreenHills、Tasking、HighTec、Cosmic)结合 |
🧩 合作工具 | CANape、INCA(用于测量/标定),TRACE32(用于 Trace) |
🔄 四、UDE 在车载 ECU 开发流程中的位置
一个典型 ECU 软件开发流程:
源代码 (C, AUTOSAR)↓
编译 & 链接↓
生成 .elf/.hex 文件↓
UDE 下载 & 调试↓
验证程序运行 (测量、标定)
UDE 在其中的作用是:
- 下载程序到 ECU;
- 设置断点、观察变量;
- 查看寄存器状态;
- 分析中断、任务调度、时间行为;
- Trace 程序执行轨迹;
- 与其他工具(如 INCA)协作进行测量和标定。
🧩 五、UDE 的自动化接口(很多企业项目会用)
UDE 支持多种自动化方式:
- Python API:可通过 Python 控制 UDE(连接目标、下载程序、设置断点、运行等)
- COM 接口(Automation Interface):可在 Windows 下被其他程序调用(比如 Jenkins 自动测试)
- UDE script:UDE 自带脚本语言
.ude
文件,可定义调试动作
示例(Python 控制 UDE):
from ude import UDEude = UDE()
ude.connect("TC397")
ude.download("my_project.elf")
ude.run()
🧠 六、UDE 与其他常见工具的区别
工具 | 厂商 | 主要功能 | 特点 |
---|---|---|---|
UDE (PLS) | PLS | 调试 / Trace / Flash | 支持多核同步调试,界面现代 |
TRACE32 (Lauterbach) | Lauterbach | 调试 / Trace | 功能极强但学习曲线陡峭 |
INCA / CANape | ETAS / Vector | 标定 / 测量 | 专注于 XCP 标定,不调试代码 |
GDB / OpenOCD | 开源 | 调试 | 低成本但对汽车 MCU 支持有限 |
🧩 七、总结一句话
🔹 UDE 是车载 ECU 开发中最常用的调试与 Trace 工具之一,
🔹 支持多核 MCU,能看寄存器、断点、变量、运行轨迹、调度行为,
🔹 还能与 INCA / CANape 协作测量标定,
🔹 并可通过 Python 自动化集成进 Jenkins 测试流程。
⚙️ 八、UDE COMAPI 调用
首先我们需要使用python的 win32com库需要安装:
pip install pywin32
下面是我在工作中使用python来调UDE实现自动化的源码,是我工作中常用的一些UDE 接口,大家也可以看UDE的帮助文档,搜索 “COM API”就可以找到一些接口的使用方法。
# -*- coding:utf-8 -*-
# author:ext.zonghuo.liu
import os
import sys
import time
import gc
import signal
import win32com.client
from common import *class UDEManager:def __init__(self):self.ProgId = "UDERunningInstanceManager"self.RunningInstanceManager = win32com.client.Dispatch(self.ProgId)self.Ude = self.RunningInstanceManager.GetInstance(0)self.Workspace = self.Ude.Workspaceself.Debugger = self.Workspace.CoreDebugger(0)def Open_andConnected_Loadelf_Start(self, WspFile):print("create new UDELauncher object")Launcher = win32com.client.Dispatch("UDELauncher")print(" Launcher: " + Launcher.Version)print("start new UDE instance")Ude = Launcher.StartAndOpenWorkspace("UDEVisualPlatform.exe", WspFile, "--silent-reload")print(" UDE version: " + Ude.VersionInfo)print("access workspace")Workspace = Ude.Workspaceprint(" Workspace: " + Workspace.ProjectTitle)print("wait for target connected")if not Workspace.WaitForTargetConnected(10000): # 10s timeoutprint("ERROR: target not connected !")exit()print("access first core debugger")Debugger = Workspace.CoreDebugger(0)Debugger.Go()def Creat_andConnected_Loadelf_setupkeeprunning_Start(self, WspFile, CfgFile, ElfFile):print("create new UDELauncher object")Launcher = win32com.client.Dispatch("UDELauncher")print(" Launcher: " + Launcher.Version)print("start new UDE instance")Ude = Launcher.StartAndCreateWorkspace("UDEVisualPlatform.exe", WspFile, CfgFile, 1)print(" UDE version: " + Ude.VersionInfo)print("access workspace")Workspace = Ude.Workspaceprint(" Workspace: " + Workspace.ProjectTitle)Debugger = Workspace.CoreDebugger(0)print("wait for target connected")if not Workspace.WaitForTargetConnected(10000): # 10s timeoutprint("ERROR: target not connected !")exit()print("access first core debugger")TargIntf = Debugger.TargIntfSetup = TargIntf.SetupSetup.SetItem("ConnOption", "KeepRunning")MultiCoreLoader = Workspace.MultiCoreLoaderif MultiCoreLoader is None:print("Failed to access MultiCoreLoader!")return Noneelse:Index1 = MultiCoreLoader.AddFile(ElfFile)MultiCoreLoader.SetLoadBin(Index1, "Controller0.Core0", False)MultiCoreLoader.SetLoadSym(Index1, "Controller0.Core0", True)MultiCoreLoader.SetLoadBin(Index1, "Controller0.Core1", True)MultiCoreLoader.SetLoadSym(Index1, "Controller0.Core1", True)MultiCoreLoader.SetLoadBin(Index1, "Controller0.Core2", False)MultiCoreLoader.SetLoadSym(Index1, "Controller0.Core2", True)MultiCoreLoader.SetLoadBin(Index1, "Controller0.Core3", False)MultiCoreLoader.SetLoadSym(Index1, "Controller0.Core3", True)MultiCoreLoader.DoDownload(0)print('load elf Core1 of bin success')Debugger.Go()CreatState = self.State()return CreatStatedef Creat_andConnected_Loadelf_Start(self, WspFile, CfgFile, ElfFile):print("create new UDELauncher object")Launcher = win32com.client.Dispatch("UDELauncher")print(" Launcher: " + Launcher.Version)print("start new UDE instance")Ude = Launcher.StartAndCreateWorkspace("UDEVisualPlatform.exe", WspFile, CfgFile, 1)print(" UDE version: " + Ude.VersionInfo)print("access workspace")Workspace = Ude.Workspaceprint(" Workspace: " + Workspace.ProjectTitle)Debugger = Workspace.CoreDebugger(0)print("wait for target connected")if not Workspace.WaitForTargetConnected(10000): # 10s timeoutprint("ERROR: target not connected !")exit()print("access first core debugger")MultiCoreLoader = Workspace.MultiCoreLoaderif MultiCoreLoader is None:print("Failed to access MultiCoreLoader!")return Noneelse:Index1 = MultiCoreLoader.AddFile(ElfFile)MultiCoreLoader.SetLoadBin(Index1, "Controller0.Core0", False)MultiCoreLoader.SetLoadSym(Index1, "Controller0.Core0", True)MultiCoreLoader.SetLoadBin(Index1, "Controller0.Core1", True)MultiCoreLoader.SetLoadSym(Index1, "Controller0.Core1", True)MultiCoreLoader.SetLoadBin(Index1, "Controller0.Core2", False)MultiCoreLoader.SetLoadSym(Index1, "Controller0.Core2", True)MultiCoreLoader.SetLoadBin(Index1, "Controller0.Core3", False)MultiCoreLoader.SetLoadSym(Index1, "Controller0.Core3", True)MultiCoreLoader.DoDownload(0)print('load elf Core1 of bin success')Debugger.Go()def Creat_andConnected(self, WspFile, CfgFile):print("create new UDELauncher object")Launcher = win32com.client.Dispatch("UDELauncher")print(" Launcher: " + Launcher.Version)print("start new UDE instance")Ude = Launcher.StartAndCreateWorkspace("UDEVisualPlatform.exe", WspFile, CfgFile, 1)print(" UDE version: " + Ude.VersionInfo)print("access workspace")Workspace = Ude.Workspaceprint(" Workspace: " + Workspace.ProjectTitle)print("wait for target connected")if not Workspace.WaitForTargetConnected(10000): # 10s timeoutprint("ERROR: target not connected !")exit()print("access first core debugger")Debugger = Workspace.CoreDebugger(0)def Load_Elf(self, ElfFile):if 0 == self.RunningInstanceManager.InstanceCount:print("ERROR: no running UDE instances found !")exit()else:MultiCoreLoader = self.Workspace.MultiCoreLoaderif MultiCoreLoader is None:print("Failed to access MultiCoreLoader!")return Noneelse:Index1 = MultiCoreLoader.AddFile(ElfFile)MultiCoreLoader.SetLoadBin(Index1, "Controller0.Core0", False)MultiCoreLoader.SetLoadSym(Index1, "Controller0.Core0", True)MultiCoreLoader.SetLoadBin(Index1, "Controller0.Core1", True)MultiCoreLoader.SetLoadSym(Index1, "Controller0.Core1", True)MultiCoreLoader.SetLoadBin(Index1, "Controller0.Core2", False)MultiCoreLoader.SetLoadSym(Index1, "Controller0.Core2", True)MultiCoreLoader.SetLoadBin(Index1, "Controller0.Core3", False)MultiCoreLoader.SetLoadSym(Index1, "Controller0.Core3", True)self.Workspace.UserProfile.SetConfigParam('NoSrcFileDlg', 'System', 'ON')MultiCoreLoader.DoDownload(0)print('load elf Core1 of bin success')def Load_Hex(self, HexFile):if 0 == self.RunningInstanceManager.InstanceCount:print("ERROR: no running UDE instances found !")exit()else:MultiCoreLoader = self.Workspace.MultiCoreLoaderif MultiCoreLoader is None:print("Failed to access MultiCoreLoader!")return Noneelse:Index1 = MultiCoreLoader.AddFile(HexFile)MultiCoreLoader.SetLoadBin(Index1, "Controller0.Core0", True)MultiCoreLoader.SetLoadSym(Index1, "Controller0.Core0", False)MultiCoreLoader.SetLoadBin(Index1, "Controller0.Core1", False)MultiCoreLoader.SetLoadSym(Index1, "Controller0.Core1", False)MultiCoreLoader.SetLoadBin(Index1, "Controller0.Core2", False)MultiCoreLoader.SetLoadSym(Index1, "Controller0.Core2", False)MultiCoreLoader.SetLoadBin(Index1, "Controller0.Core3", False)MultiCoreLoader.SetLoadSym(Index1, "Controller0.Core3", False)MultiCoreLoader.DoDownload(0)print('load elf Core0 of bin success')def RemoveAllFiles(self):MultiCoreLoader = self.Workspace.MultiCoreLoaderif 0 == self.RunningInstanceManager.InstanceCount:print("ERROR: no running UDE instances found !")exit()else:if MultiCoreLoader is None:print("Failed to access MultiCoreLoader!")return Noneelse:MultiCoreLoader.RemoveAllFiles()print('Remove Success')def Init(self, cfgpath):State = ''if 0 == self.RunningInstanceManager.InstanceCount:print("ERROR: no running UDE instances found !")exit()else:self.Debugger.Init(cfgpath)State = self.Debugger.Stateprint('Start Success = ', State)return Statedef SaveWorkspace(self):State = ''if 0 == self.RunningInstanceManager.InstanceCount:print("ERROR: no running UDE instances found !")exit()else:self.Debugger.SaveWorkspace()State = self.Debugger.Stateprint('Start Success = ', State)return Statedef SaveWorkspaceAs(self, NewFilePath):State = ''if 0 == self.RunningInstanceManager.InstanceCount:print("ERROR: no running UDE instances found !")exit()else:self.Debugger.SaveWorkspaceAs(NewFilePath)State = self.Debugger.Stateprint('Start Success = ', State)return Statedef Close(self):if 0 == self.RunningInstanceManager.InstanceCount:print("ERROR: no running UDE instances found !")exit()self.Ude.CloseWorkspace()print("finished")def Cleanup(self):if 0 == self.RunningInstanceManager.InstanceCount:print("ERROR: no running UDE instances found !")exit()self.RunningInstanceManager.Cleanup()print("finished")def StopInstance(self):if 0 == self.RunningInstanceManager.InstanceCount:print("ERROR: no running UDE instances found !")exit()print("release objects and close UDE instance")self.RunningInstanceManager.StopInstance(self.Ude)print("finished")def ReadVariable(self, VariableName):VariableValue = 99if 0 == self.RunningInstanceManager.InstanceCount:print("ERROR: no running UDE instances found !")exit()if not self.Workspace.CheckTargetConnected():VariableValue = self.Debugger.ReadVariable(VariableName)else:try:VariableValue = self.Debugger.ReadVariable(VariableName)except:passreturn VariableValuedef WriteVariable(self, VariableName, NewValue):WriteStatus = 0if 0 == self.RunningInstanceManager.InstanceCount:print("ERROR: no running UDE instances found !")return WriteStatusif not self.Workspace.CheckTargetConnected():if not self.Workspace.WaitForTargetConnected(10): # 10s timeoutprint("ERROR: target not connected !")else:self.Debugger.WriteVariable(VariableName, NewValue)ReadWriteValue = self.Debugger.ReadVariable(VariableName)if str(ReadWriteValue) == str(NewValue):WriteStatus = 1print('Write ', VariableName, '=', NewValue)return WriteStatusdef BreakProgram(self):BreakStatus = 0if 0 == self.RunningInstanceManager.InstanceCount:print("ERROR: no running UDE instances found !")exit()if not self.Workspace.CheckTargetConnected():print("ERROR: target not connected !")exit()else:self.Debugger.Break()if not self.Debugger.WaitForHalt(3000): # 3s timeoutprint("ERROR: not halted at breakpoint !")else:State = self.Debugger.Stateif State == 0:BreakStatus = 1print('Break Success = ', State)return BreakStatusdef StartProgram(self):StartStatus = 0if 0 == self.RunningInstanceManager.InstanceCount:print("ERROR: no running UDE instances found !")exit()else:self.Debugger.Go()State = self.Debugger.Stateif State == 1:StartStatus = 1print('Start Success = ', State)return StartStatusdef State(self):core0_State = ''core1_State = ''core2_State = ''core3_State = ''State = ''if 0 == self.RunningInstanceManager.InstanceCount:print("ERROR: no running UDE instances found !")exit()else:core0_State = self.Debugger.Statecore1_State = self.Debugger.Statecore2_State = self.Debugger.Statecore3_State = self.Debugger.StateState = str(core0_State) + str(core1_State) + str(core2_State) + str(core3_State)print('State=', State)return Statedef LoadAndFlash(self, elfpath, Options):State = ''if 0 == self.RunningInstanceManager.InstanceCount:print("ERROR: no running UDE instances found !")exit()else:State = self.Debugger.GetState()if 1 == State:print(" Core is running")elif 2 == State:print(" Core is inactive")else:print(" Core is halted")if not self.Debugger.LoadAndFlash(elfpath, Options):if not self.Debugger.LoadAndFlash(elfpath):print("ERROR: failed to load elf file !")exit()print("start target application")self.Debugger.Go()if not self.Workspace.WaitForAllCoresRunning(10000, False): # 1s timeoutprint("ERROR: target not running !")exit()else:print("wait a second")self.Workspace.Sleep(1000)State = self.Debugger.Stateprint('Start Success = ', State)return Statedef LoadHexDataFile(self, hexpath, Options):State = ''if 0 == self.RunningInstanceManager.InstanceCount:print("ERROR: no running UDE instances found !")exit()else:State = self.Debugger.GetState()if 1 == State:print(" Core is running")elif 2 == State:print(" Core is inactive")else:print(" Core is halted")if not self.Debugger.LoadHexDataFile(hexpath, True, Options):print('load and FLASH-program hex file')print("start target application")self.Debugger.Go()if not self.Workspace.WaitForAllCoresRunning(10000, False): # 1s timeoutprint("ERROR: target not running !")exit()else:print("wait a second")self.Workspace.Sleep(1000)State = self.Debugger.Stateprint('Start Success = ', State)return Statedef Reset(self):ResetStatus = 0if 0 == self.RunningInstanceManager.InstanceCount:print("ERROR: no running UDE instances found !")exit()else:self.Debugger.ResetTarget()State = self.Debugger.Stateif State == 0:ResetStatus = 1print('Reset Success = ', State)return ResetStatusdef Restart(self):State = ''if 0 == self.RunningInstanceManager.InstanceCount:print("ERROR: no running UDE instances found !")exit()else:self.Debugger.ReloadProgram()State = self.Debugger.Stateprint('Restart Success = ', State)return Statedef ConnectTarget(self):ConnectStatus = 'false'if 0 == self.RunningInstanceManager.InstanceCount:print("ERROR: no running UDE instances found !")exit()else:self.Workspace.ConnectTarget(3000)Debugger1 = self.Workspace.CoreDebugger(0)Debugger2 = self.Workspace.CoreDebugger(1)Debugger3 = self.Workspace.CoreDebugger(2)Debugger4 = self.Workspace.CoreDebugger(3)core0_State = Debugger1.Statecore1_State = Debugger2.Statecore2_State = Debugger3.Statecore3_State = Debugger4.Stateif (core0_State == 1) and (core1_State == 1) and (core2_State == 1) and (core3_State == 1):State = 1elif (core0_State == 0) and (core1_State == 2) or (core2_State == 2) or (core3_State == 2):State = 2elif (core0_State == 0) and (core1_State == 0) and (core2_State == 0) and (core3_State == 0):State = 0else:State = 3return Statedef DisconnectTarget(self):ProgId = "UDERunningInstanceManager"RunningInstanceManager = win32com.client.Dispatch(ProgId)Ude = RunningInstanceManager.GetInstance(0)Workspace = Ude.WorkspaceWorkspace.DisconnectTarget(3000)Debugger1 = Workspace.CoreDebugger(0)Debugger2 = Workspace.CoreDebugger(1)Debugger3 = Workspace.CoreDebugger(2)Debugger4 = Workspace.CoreDebugger(3)core0_State = Debugger1.Statecore1_State = Debugger2.Statecore2_State = Debugger3.Statecore3_State = Debugger4.Stateif (core0_State == 0) and (core1_State == 0) and (core2_State == 0) and (core3_State == 0): # 3s timeoutprint("target disconnected !")State = 0else:State = 1print('ERROR: target connected')return Statedef SetupCommDev(self, DeviceNumber, UAD):TargIntf = self.Debugger.TargIntfSetup = TargIntf.SetupSetup.SetItem("PortType", "CommDev")Setup.SetItem("CommDevSel", "DeviceNumber=" + DeviceNumber, "PortType=USB", "Type=" + UAD)def SetBreakPoint_andWrite(self, Breakpoint, VariableName, NewValue):if 0 == self.RunningInstanceManager.InstanceCount:print("ERROR: no running UDE instances found !")exit()if not self.Workspace.CheckTargetConnected():print("ERROR: target not connected !")exit()else:print("set a breakpoint and wait for halt")self.Debugger.Breakpoints.Add(Breakpoint)self.Debugger.WriteVariable(VariableName, NewValue) # trigger halt at breakpointif not self.Debugger.WaitForHalt(3000): # 3s timeoutprint("ERROR: not halted at breakpoint !")exit()def BreakPointAdd(self, Function):if 0 == self.RunningInstanceManager.InstanceCount:print("ERROR: no running UDE instances found !")exit()if not self.Workspace.CheckTargetConnected():print("ERROR: target not connected !")exit()else:print("set a breakpoint and wait for halt")self.Debugger.Breakpoints.Add(Function)if not self.Debugger.WaitForHalt(3000): # 3s timeoutprint("ERROR: not halted at breakpoint !")exit()def BreakPointAddAndGetResult(self, Function):if 0 == self.RunningInstanceManager.InstanceCount:print("ERROR: no running UDE instances found !")exit()if not self.Workspace.CheckTargetConnected():print("ERROR: target not connected !")exit()else:print("set a breakpoint and wait for halt")self.Debugger.Breakpoints.AddAndGetResult(Function)if not self.Debugger.WaitForHalt(3000): # 3s timeoutprint("ERROR: not halted at breakpoint !")exit()def DoEventsUntil(self, VariableName):holdtime = 0changetime = 0value3 = 0value2 = 0time1 = 0time2 = 0time3 = 0time4 = 0time5 = 0t = time.perf_counter()value = self.ReadVariable(VariableName)while 1:value1 = self.ReadVariable(VariableName)if value != value1:time1 = time.perf_counter()value2 = value1breakif time.perf_counter() - t > 120:print(time.perf_counter() - t)breakwhile 1:value3 = self.ReadVariable(VariableName)if value2 != value3:time2 = time.perf_counter()value4 = value3breakif time.perf_counter() - t > 120:print(time.perf_counter() - t)breakwhile 1:value4 = self.ReadVariable(VariableName)if value3 != value4:time3 = time.perf_counter()if time.perf_counter() - t > 120:print(time.perf_counter() - t)breakwhile 1:value5 = self.ReadVariable(VariableName)if value4 != value5:time4 = time.perf_counter()if time.perf_counter() - t > 120:print(time.perf_counter() - t)breakchangetime = time4 - time3print(270, changetime)return changetimedef ReadArrayVariable(self, Addr, Array, Options):VariableValue = ''if 0 == self.RunningInstanceManager.InstanceCount:print("ERROR: no running UDE instances found !")exit()if not self.Workspace.CheckTargetConnected():print("ERROR: target not connected !")exit()else:VariableValue = self.Debugger.ReadArray(Addr, Array, Options)print('VariableValue=', VariableValue)return VariableValuedef ReadMemory8(self, Adr):VariableValue = ''if 0 == self.RunningInstanceManager.InstanceCount:print("ERROR: no running UDE instances found !")exit()if not self.Workspace.CheckTargetConnected():print("ERROR: target not connected !")exit()else:VariableValue = self.Debugger.ReadMemory8(Adr)print('VariableValue=', VariableValue)return VariableValuedef ReadMemory16(self, Adr):VariableValue = ''if 0 == self.RunningInstanceManager.InstanceCount:print("ERROR: no running UDE instances found !")exit()if not self.Workspace.CheckTargetConnected():print("ERROR: target not connected !")exit()else:VariableValue = self.Debugger.ReadMemory16(Adr)print('VariableValue=', VariableValue)return VariableValuedef ReadMemory32(self, Adr):VariableValue = ''if 0 == self.RunningInstanceManager.InstanceCount:print("ERROR: no running UDE instances found !")exit()if not self.Workspace.CheckTargetConnected():print("ERROR: target not connected !")exit()else:VariableValue = self.Debugger.ReadMemory32(Adr)print('VariableValue=', VariableValue)return VariableValuedef UDE_TaskKill(self):ReturnInfo = os.popen('tasklist | findstr "ude.exe"').read()print(ReturnInfo)if "ude.exe" in ReturnInfo:os.system('taskkill /F /IM ude.exe')print('关闭UDE文件')return 0def AccessRunningUde_TaskKill(self):ReturnInfo = os.popen('tasklist | findstr "AccessRunningUde.exe"').read()if "AccessRunningUde.exe" in ReturnInfo:os.system('taskkill /F /IM AccessRunningUde.exe')print('关闭 AccessRunningUde.exe')return 0def VarValueCTime(self, VariableName, VarValueArray, RunningTime):Ctime0 = {}RunningTime = int(RunningTime)time00 = time.time()while True:VarValue0 = str(self.ReadVariable(VariableName))if VarValue0 in VarValueArray:VarValueArray.remove(VarValue0)time0 = time.time()while True:VarValue = str(self.ReadVariable(VariableName))time1 = time.time()if VarValue0 != VarValue:RTime = time1 - time0Ctime0.update({VarValue0: RTime})breakelse:RTime1 = time1 - time0if RTime1 > RunningTime:breaktime2 = time.time()RTime2 = time2 - time00if RTime2 > RunningTime:passprint(VariableName, Ctime0)return Ctime0def TryConnectAgain(self):ConnectStatus = 'false'try:UDE_State = self.State()if UDE_State == 1:ConnectStatus = 'true'print('UDE is Running')else:print('try reseting')Result = self.ConnectTarget()if Result == 'true':ConnectStatus = 'true'print('UDE is Running')else:self.Reset()Result = self.StartProgram()if Result == 'true':ConnectStatus = 'true'print('UDE is Running')except IOError:print('请保持UDE连接')return ConnectStatus
希望能帮助到大家提升技能,感谢大家查阅,有疑问可以评论区见。