转自python + QXDM5高通平台通过自动化截取log方法及代码
准备工作:
1.安装QXDM5
2.配置adb 环境变量
3.使用python 3以上
4.完成代码如下
1 import sys 2 import time 3 import os 4 5 if sys.platform.startswith("linux"): 6 sys.path.append('/opt/qcom/QXDM/Support/python') 7 8 elif sys.platform.startswith("win"): 9 sys.path.append('C:\Program Files (x86)\Qualcomm\QXDM5\Support\python') #QXDM5的默认路径 10 sys.path.append('C:\Program Files (x86)\Qualcomm\QUTS\Support\python') 11 12 elif sys.platform.startswith("darwin"): 13 sys.path.append('/Applications/Qualcomm/QUTS/QUTS.app/Contents/Support/python') 14 15 import QutsClient 16 import QxdmAutomationClient 17 import QxdmAutomationService.ttypes 18 19 20 class deviceManager(object): 21 #通过模块的devicesID获取QXDM需要连接设备的devicehandle, protocolHandle 22 def getDeviceInfo(self,devid,getPortName="Diagnostics"): 23 protocolHandle = "" 24 deviceHandle = "" 25 comport = "" 26 try: 27 try: 28 client = QutsClient.QutsClient("QUTS Sample") 29 except Exception as e: 30 logging.info("Exception starting client:%s" %e) 31 32 if client is None: 33 logging.info('QUTS客户端未实例化,请确认是否安装....') 34 else: 35 logging.info('初始化客户端....') 36 37 deviceManager = client.getDeviceManager() 38 39 time.sleep(1) 40 41 deviceList = deviceManager.getDeviceList() 42 for element in deviceList: 43 if element.adbSerialNumber == devid: 44 a = element.protocols 45 for x in a: 46 print(getPortName,x.description) 47 if getPortName in x.description: 48 protocolHandle = x.protocolHandle 49 deviceHandle = x.deviceHandle 50 comport = x.description.split("(")[-1].replace(")","") 51 break 52 53 print(deviceHandle, protocolHandle, comport) 54 return deviceHandle, protocolHandle, comport 55 except Exception as e: 56 logging.info("获取端口信息失败,失败原因%s" %e) 57 return deviceHandle, protocolHandle, comport 58 59 60 61 62 class ControlQXDM(object): 63 def startQXDM(self,devid,dmcFile="yourdmcFiledir"): 64 deviceHandle, protocolHandle, comport = deviceManager().getDeviceInfo(devid) 65 print("Creating QXDM Automation client\n") 66 qxdm_auto_client = QxdmAutomationClient.QxdmAutomationClient("OpenQXDMLog") 67 qxdmAutomationHandle = qxdm_auto_client.getQxdmAutomationManager() 68 69 # Init Service 70 init = qxdmAutomationHandle.InitializeService() 71 72 if (init == False): 73 logging.info("初始化QXDM失败,已存在该服务....") 74 75 qxdmAutomationHandle.SetVisible(True) 76 77 retVal = qxdmAutomationHandle.LoadConfig(os.getcwd() + dmcFile) 78 if not retVal: 79 print("导入dmc配置文件失败,无法开启log,请查看是否存在该文件%s...." %os.getcwd() + dmcFile) 80 return False 81 # hdffile = "C:\\Temp\\testlog\\nas_logging.hdf" 82 # retVal = qxdmAutomationHandle.LoadItemStore(hdffile) 83 84 deviceInfo = QxdmAutomationService.ttypes.ConnectDeviceInfo(int(deviceHandle), int(protocolHandle)) 85 86 retVal = qxdmAutomationHandle.ConnectToDevice(deviceInfo) 87 if not retVal: 88 print("连接设备失败....") 89 return False 90 return qxdmAutomationHandle 91 92 # 仅保存可以使用如下方法: 93 # retVal = obj.SaveItemStore(logName) 94 95 def stopQxdm(self,obj,logName): 96 try: 97 obj.DisconnectFromDevice() 98 retVal = obj.SaveItemStore(logName) 99 if not retVal: 100 print("保存QXDM log失败....") 101 return False 102 103 print("Closing QXDM session in 5 seconds") 104 time.sleep(5) 105 obj.Close() 106 except Exception as e: 107 print("保存log失败,失败原因:%s" %e) 108 return False 109 110 111 if __name__ == '__main__': 112 #调用参考如下: 113 114 obj=ControlQXDM().startQXDM("1234567") #启动QXDM,你会看到QXDM窗口正在截取log 115 116 time.sleep(10) 117 118 119 120 logName = "d:\\123-1.hdf" 121 retVal = obj.SaveItemStore(logName) #保存并清空log 122 print(retVal) 123 logName = "d:\\1\\123-2.hdf" 124 125 time.sleep(10) 126 127 128 ControlQXDM().stopQxdm(obj,"d:\\456.hdf") #保存并关闭QXDM
标签:protocolHandle,deviceHandle,log,QXDM,python,QXDM5,print,retVal From: https://www.cnblogs.com/edenpei/p/python.html