当前位置: 首页 > news >正文

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

一、依赖库

import subprocess
import serial
from serial.tools import list_ports
import logging
import time

二、代码

import subprocessimport serial
from serial.tools import list_ports
import logging
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}')#         breakprint("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 = 0while 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...")breakelse:print("Device not found. Switching modes and retrying...")openAdb(com)count += 1if count >= 5:print("Please check if the environment is OK")breakexcept subprocess.CalledProcessError as e:print("An error occurred while executing adb command:", e)breakif __name__ == '__main__':com = 'COM24'# openAdb(com)check_adb(com)

三、使用场景

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

http://www.lryc.cn/news/434001.html

相关文章:

  • ssm微信小程序校园失物招领论文源码调试讲解
  • iOS 15推出后利用邮件打开率的7种方法
  • 以太网--TCP/IP协议(一)
  • LeetCode刷题:找到第K大的元素
  • HTML页面配置高德地图,获取位置
  • HTTrack
  • 干货分享|分享一款微软出品的工作效率神器 PowerToys
  • 神经网络的线性部分和非线性部分
  • 微信支付开发避坑指南
  • Qt5.4.1连接odbc驱动操作达梦数据库
  • 计算机组成原理(第一课)
  • 计算机网络练级第一级————认识网络
  • Java基于微信小程序的家庭财务管理系统,附源码
  • P2343 宝石管理系统
  • Spring6梳理6——依赖注入之Setter和构造器注入
  • 【C++】C++入门基础,详细介绍命名空间,缺省参数,函数重载,引用,内联函数等
  • Android使用Room后无法找到字符BR
  • 网络通讯安全基础知识(加密+解密+验签+证书)
  • [数据集][目标检测]石油泄漏检测数据集VOC+YOLO格式6633张1类别
  • 【Oracle篇】全面理解优化器和SQL语句的解析步骤(含执行计划的详细分析和四种查看方式)(第二篇,总共七篇)
  • 都2024年了还不明白Redis持久化?RDB文件、AOF文件、AOF重写
  • 浅谈Unity协程的工作机制
  • 数学建模_数据预处理流程(全)
  • 深入解析Flink SQL:基本概念与高级应用
  • 计算机的发展史和基本结构
  • VSTO常见的异常
  • 【H2O2|全栈】关于HTML(3)HTML基础(二)
  • 前端AST
  • 基于EPS32C3电脑远程开机模块设计
  • 深度解析 Netty 性能卓越的背后原因