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):

python 复制代码
from ude import UDE

ude = 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库需要安装:

python 复制代码
pip install pywin32

下面是我在工作中使用python来调UDE实现自动化的源码,是我工作中常用的一些UDE 接口,大家也可以看UDE的帮助文档,搜索 "COM API"就可以找到一些接口的使用方法。

python 复制代码
# -*- 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.Workspace
        self.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.Workspace
        print("  Workspace: " + Workspace.ProjectTitle)

        print("wait for target connected")
        if not Workspace.WaitForTargetConnected(10000):  # 10s timeout
            print("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.Workspace
        print("  Workspace: " + Workspace.ProjectTitle)
        Debugger = Workspace.CoreDebugger(0)

        print("wait for target connected")
        if not Workspace.WaitForTargetConnected(10000):  # 10s timeout
            print("ERROR: target not connected !")
            exit()

        print("access first core debugger")
        TargIntf = Debugger.TargIntf
        Setup = TargIntf.Setup
        Setup.SetItem("ConnOption", "KeepRunning")

        MultiCoreLoader = Workspace.MultiCoreLoader
        if MultiCoreLoader is None:
            print("Failed to access MultiCoreLoader!")
            return None
        else:
            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 CreatState

    def 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.Workspace
        print("  Workspace: " + Workspace.ProjectTitle)
        Debugger = Workspace.CoreDebugger(0)

        print("wait for target connected")
        if not Workspace.WaitForTargetConnected(10000):  # 10s timeout
            print("ERROR: target not connected !")
            exit()

        print("access first core debugger")
        MultiCoreLoader = Workspace.MultiCoreLoader
        if MultiCoreLoader is None:
            print("Failed to access MultiCoreLoader!")
            return None
        else:
            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.Workspace
        print("  Workspace: " + Workspace.ProjectTitle)

        print("wait for target connected")
        if not Workspace.WaitForTargetConnected(10000):  # 10s timeout
            print("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.MultiCoreLoader
            if MultiCoreLoader is None:
                print("Failed to access MultiCoreLoader!")
                return None
            else:
                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.MultiCoreLoader
            if MultiCoreLoader is None:
                print("Failed to access MultiCoreLoader!")
                return None
            else:
                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.MultiCoreLoader
        if 0 == self.RunningInstanceManager.InstanceCount:
            print("ERROR: no running UDE instances found !")
            exit()
        else:
            if MultiCoreLoader is None:
                print("Failed to access MultiCoreLoader!")
                return None
            else:
                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.State
            print('Start Success = ', State)
        return State

    def SaveWorkspace(self):
        State = ''
        if 0 == self.RunningInstanceManager.InstanceCount:
            print("ERROR: no running UDE instances found !")
            exit()
        else:
            self.Debugger.SaveWorkspace()
            State = self.Debugger.State
            print('Start Success = ', State)
        return State

    def 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.State
            print('Start Success = ', State)
        return State

    def 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 = 99
        if 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:
                pass
        return VariableValue

    def WriteVariable(self, VariableName, NewValue):
        WriteStatus = 0
        if 0 == self.RunningInstanceManager.InstanceCount:
            print("ERROR: no running UDE instances found !")
            return WriteStatus
        if not self.Workspace.CheckTargetConnected():
            if not self.Workspace.WaitForTargetConnected(10):  # 10s timeout
                print("ERROR: target not connected !")
        else:
            self.Debugger.WriteVariable(VariableName, NewValue)
            ReadWriteValue = self.Debugger.ReadVariable(VariableName)
            if str(ReadWriteValue) == str(NewValue):
                WriteStatus = 1
                print('Write ', VariableName, '=', NewValue)
        return WriteStatus

    def BreakProgram(self):
        BreakStatus = 0
        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:
            self.Debugger.Break()
            if not self.Debugger.WaitForHalt(3000):  # 3s timeout
                print("ERROR: not halted at breakpoint !")
            else:
                State = self.Debugger.State
                if State == 0:
                    BreakStatus = 1
                    print('Break Success = ', State)
        return BreakStatus

    def StartProgram(self):
        StartStatus = 0
        if 0 == self.RunningInstanceManager.InstanceCount:
            print("ERROR: no running UDE instances found !")
            exit()
        else:
            self.Debugger.Go()
            State = self.Debugger.State
            if State == 1:
                StartStatus = 1
                print('Start Success = ', State)
        return StartStatus

    def 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.State
            core1_State = self.Debugger.State
            core2_State = self.Debugger.State
            core3_State = self.Debugger.State
            State = str(core0_State) + str(core1_State) + str(core2_State) + str(core3_State)
            print('State=', State)
        return State

    def 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 timeout
                print("ERROR: target not running !")
                exit()
            else:
                print("wait a second")
                self.Workspace.Sleep(1000)
                State = self.Debugger.State
                print('Start Success = ', State)
        return State

    def 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 timeout
                print("ERROR: target not running !")
                exit()
            else:
                print("wait a second")
                self.Workspace.Sleep(1000)
                State = self.Debugger.State
                print('Start Success = ', State)
        return State

    def Reset(self):
        ResetStatus = 0
        if 0 == self.RunningInstanceManager.InstanceCount:
            print("ERROR: no running UDE instances found !")
            exit()
        else:
            self.Debugger.ResetTarget()
            State = self.Debugger.State
            if State == 0:
                ResetStatus = 1
                print('Reset Success = ', State)
        return ResetStatus

    def Restart(self):
        State = ''
        if 0 == self.RunningInstanceManager.InstanceCount:
            print("ERROR: no running UDE instances found !")
            exit()
        else:
            self.Debugger.ReloadProgram()
            State = self.Debugger.State
            print('Restart Success = ', State)
        return State

    def 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.State
            core1_State = Debugger2.State
            core2_State = Debugger3.State
            core3_State = Debugger4.State
            if (core0_State == 1) and (core1_State == 1) and (core2_State == 1) and (core3_State == 1):
                State = 1
            elif (core0_State == 0) and (core1_State == 2) or (core2_State == 2) or (core3_State == 2):
                State = 2
            elif (core0_State == 0) and (core1_State == 0) and (core2_State == 0) and (core3_State == 0):
                State = 0
            else:
                State = 3
        return State

    def DisconnectTarget(self):
        ProgId = "UDERunningInstanceManager"
        RunningInstanceManager = win32com.client.Dispatch(ProgId)
        Ude = RunningInstanceManager.GetInstance(0)
        Workspace = Ude.Workspace
        Workspace.DisconnectTarget(3000)
        Debugger1 = Workspace.CoreDebugger(0)
        Debugger2 = Workspace.CoreDebugger(1)
        Debugger3 = Workspace.CoreDebugger(2)
        Debugger4 = Workspace.CoreDebugger(3)
        core0_State = Debugger1.State
        core1_State = Debugger2.State
        core2_State = Debugger3.State
        core3_State = Debugger4.State
        if (core0_State == 0) and (core1_State == 0) and (core2_State == 0) and (core3_State == 0):  # 3s timeout
            print("target disconnected !")
            State = 0
        else:
            State = 1
            print('ERROR: target connected')
        return State

    def SetupCommDev(self, DeviceNumber, UAD):
        TargIntf = self.Debugger.TargIntf
        Setup = TargIntf.Setup
        Setup.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 breakpoint
            if not self.Debugger.WaitForHalt(3000):  # 3s timeout
                print("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 timeout
                print("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 timeout
                print("ERROR: not halted at breakpoint !")
                exit()

    def DoEventsUntil(self, VariableName):
        holdtime = 0
        changetime = 0
        value3 = 0
        value2 = 0
        time1 = 0
        time2 = 0
        time3 = 0
        time4 = 0
        time5 = 0
        t = time.perf_counter()
        value = self.ReadVariable(VariableName)
        while 1:
            value1 = self.ReadVariable(VariableName)
            if value != value1:
                time1 = time.perf_counter()
                value2 = value1
                break
            if time.perf_counter() - t > 120:
                print(time.perf_counter() - t)
                break
        while 1:
            value3 = self.ReadVariable(VariableName)
            if value2 != value3:
                time2 = time.perf_counter()
                value4 = value3
                break
            if time.perf_counter() - t > 120:
                print(time.perf_counter() - t)
                break
        while 1:
            value4 = self.ReadVariable(VariableName)
            if value3 != value4:
                time3 = time.perf_counter()

            if time.perf_counter() - t > 120:
                print(time.perf_counter() - t)
                break
        while 1:
            value5 = self.ReadVariable(VariableName)
            if value4 != value5:
                time4 = time.perf_counter()
            if time.perf_counter() - t > 120:
                print(time.perf_counter() - t)
                break
        changetime = time4 - time3
        print(270, changetime)
        return changetime

    def 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 VariableValue

    def 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 VariableValue

    def 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 VariableValue

    def 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 VariableValue

    def 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 0

    def 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 0

    def 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 - time0
                        Ctime0.update({VarValue0: RTime})
                        break
                    else:
                        RTime1 = time1 - time0
                        if RTime1 > RunningTime:
                            break
        time2 = time.time()
        RTime2 = time2 - time00
        if RTime2 > RunningTime:
            pass
        print(VariableName, Ctime0)
        return Ctime0

    def 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

希望能帮助到大家提升技能,感谢大家查阅,有疑问可以评论区见

相关推荐
Full Stack Developme3 小时前
java.nio 包详解
java·python·nio
新手村领路人3 小时前
opencv gpu cuda python c++版本测试代码
python·opencv·cuda
高洁014 小时前
大模型-高效优化技术全景解析:微调 量化 剪枝 梯度裁剪与蒸馏 下
人工智能·python·深度学习·神经网络·知识图谱
white-persist4 小时前
CSRF 漏洞全解析:从原理到实战
网络·python·安全·web安全·网络安全·系统安全·csrf
Bellafu6665 小时前
本地搭建EXAM-MASTER考试系统
python
开心-开心急了5 小时前
Flask入门教程——李辉 第三章 关键知识梳理
后端·python·flask
rannn_1115 小时前
【学以致用|python自动化办公】OCR批量识别自动存为Excel(批量识别发票)
python·ocr·excel·财务
AI视觉网奇6 小时前
pycharm 默认终端设置 cmd
ide·python·pycharm
言之。6 小时前
LiteLLM:让LLM调用变得简单统一
后端·python·flask