外接串口板,通过串口打开adb模式

打印 上一主题 下一主题

主题 992|帖子 992|积分 2976

一、依赖库

  1. import subprocess
  2. import serial
  3. from serial.tools import list_ports
  4. import logging
  5. import time
复制代码
二、代码

  1. import subprocess
  2. import serial
  3. from serial.tools import list_ports
  4. import logging
  5. import timedef openAdb(com):    # com = []    # for i in list_ports.comports():    #     if 'USB Serial' in i.description:    #         print(i.description)    #         com = i.name    #         print(com)    #         logging.debug(f'serial port:{com}')    #         break    print("try to open adb")    ser = serial.Serial(com, 115200, timeout=0.1)    if ser.is_open:        ser.write(b"\n")        time.sleep(1)        ser.write(b"root\n")        ser.write(b"\n")        time.sleep(1)        ser.write(b"Visteon@JMC23651\n")        time.sleep(1)        ser.write(b"dtach -a /tmp/glconsole\n")        ser.write(b"su\n")        ser.write(b"Vist@jmc789\n")        time.sleep(1)        ser.write(b"start setmode_device\n")        time.sleep(1)    ser.close()def check_adb(com):    count = 0    while True:        try:            subprocess.run(["adb", "kill-server"], check=True)            subprocess.run(["adb", "start-server"], check=True)            output = subprocess.check_output("adb devices", shell=True).decode('utf-8')            # print("Output of adb devices:", output.strip())            devices = []            lines = output.strip().split('\n')            for line in lines[1:]:                if '\tdevice' in line:                    device_info = line.split('\t')[0]                    devices.append(device_info)            print(devices)            if devices is not None and len(devices) > 0:                print("Device found. Performing operations...")                break            else:                print("Device not found. Switching modes and retrying...")                openAdb(com)                count += 1                if count >= 5:                    print("Please check if the environment is OK")                    break        except subprocess.CalledProcessError as e:            print("An error occurred while executing adb command:", e)            breakif __name__ == '__main__':    com = 'COM24'    # openAdb(com)    check_adb(com)
复制代码
三、使用场景

必要外接继电器,通过串口下令打开车机调试模式


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

悠扬随风

金牌会员
这个人很懒什么都没写!
快速回复 返回顶部 返回列表