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

南宁市网站开发建设市场推广方式有哪几种

南宁市网站开发建设,市场推广方式有哪几种,网站开发发和后台开发有什么区别,东莞建设网官前言 在嵌入式设备的OTA场景测试和其他断电上电测试过程中,有的场景发生在夜晚或者随时可能发生,这个时候不可能24h人工盯着,需要自动化抓取串口日志处罚断电上电操作。 下面的python脚本可以实现自动抓取串口指定关键词,然后触发…

前言

在嵌入式设备的OTA场景测试和其他断电上电测试过程中,有的场景发生在夜晚或者随时可能发生,这个时候不可能24h人工盯着,需要自动化抓取串口日志处罚断电上电操作。
下面的python脚本可以实现自动抓取串口指定关键词,然后触发继电器的主动断电上电操作,具体场景是在我实际开发项目中,有一个静默升级的功能,在夜间静默推送升级功能,需要做下载过程的随机断电防止出现升级过程卡死。

我写了以下的工具,可以捕捉mobxterm上面的日志指定关键字,当扫描到指定关键字进行断电或者上电的测试,完成夜间的随机物理断电测试。

准备工作

  1. 带有ch340串口芯片或者其他串口芯片的继电器模块
    在这里插入图片描述

  2. mobxterm软件

  3. python脚本

代码

python脚本如下,python3环境执行


# *Copyright(C),2025-20xx
# *FileName:  
# *Author:  ljl
# *Version:  
# *Date:  
# *Description:  import serial
import time
import oslast_mod_time = 0
# 监控的日志文件路径
log_file_path = "[com COM3]  (2025-01-09_152828)  罗的板子(COM3).log"# 你想要监控的关键词,这里设置为 "percent: 40"
keywords = ["percent: 40"]# 设置串口参数
serial_port = 'COM2'  # 请根据你的实际情况更改串口号
baud_rate = 9600  # 根据你的设备设置正确的波特率# 发送十六进制串口指令的函数
def send_hex_serial_command(port, baudrate, hex_command):# 打开串口ser = serial.Serial(port, baudrate, timeout=1)try:# 将十六进制字符串转换为字节对象command_bytes = bytes.fromhex(hex_command)# 发送指令ser.write(command_bytes)except Exception as e:print(f"发生错误: {e}")finally:# 关闭串口ser.close()def elect_init():print("初始化继电器,执行串口上电程序!")# 执行串口上电hex_command_to_send = "A0 01 00 A1"  # 断电指令send_hex_serial_command(serial_port, baud_rate, hex_command_to_send)hex_command_to_send = "A0 02 00 A2"  # 断电指令send_hex_serial_command(serial_port, baud_rate, hex_command_to_send)hex_command_to_send = "A0 03 00 A3"  # 断电指令send_hex_serial_command(serial_port, baud_rate, hex_command_to_send)hex_command_to_send = "A0 04 00 A4"  # 断电指令send_hex_serial_command(serial_port, baud_rate, hex_command_to_send)# 根据关键词执行串口断电操作
def execute_script():print("找到 'percent: 40',执行串口断电程序!")# 执行串口断电hex_command_to_send = "A0 01 01 A2"  # 请替换为你实际要发送的十六进制指令,用空格分隔每个字节send_hex_serial_command(serial_port, baud_rate, hex_command_to_send)hex_command_to_send = "A0 02 01 A3"  # 请替换为你实际要发送的十六进制指令,用空格分隔每个字节send_hex_serial_command(serial_port, baud_rate, hex_command_to_send)hex_command_to_send = "A0 03 01 A4"  # 请替换为你实际要发送的十六进制指令,用空格分隔每个字节send_hex_serial_command(serial_port, baud_rate, hex_command_to_send)hex_command_to_send = "A0 04 01 A5"  # 请替换为你实际要发送的十六进制指令,用空格分隔每个字节send_hex_serial_command(serial_port, baud_rate, hex_command_to_send)# 监控日志文件的函数
def monitor_log():global last_mod_timestart_time = time.time()  # 获取程序开始时的时间print("开始监控日志文件...")try:while True:# 获取文件的最后修改时间current_mod_time = os.path.getmtime(log_file_path)# 如果文件发生更新(修改时间不同),重新读取并检查文件if current_mod_time > last_mod_time:last_mod_time = current_mod_time  # 更新最后修改时间with open(log_file_path, "r") as log_file:# 从文件开头开始读取for line in log_file:# 检查日志行是否包含关键词for keyword in keywords:if keyword in line:# 计算当前时间与开始时间的间隔elapsed_time = time.time() - start_timeprint(f"找到关键词 '{keyword}',执行串口指令")print(f"当前时间:{time.strftime('%H:%M:%S', time.gmtime(elapsed_time))},已运行 {elapsed_time:.2f} 秒")execute_script()break# 每10秒钟再次执行一次检查time.sleep(10)except FileNotFoundError:print(f"错误: 无法打开日志文件 {log_file_path},文件未找到。")except IOError as e:print(f"错误: 打开日志文件时发生IO错误: {e}")if __name__ == "__main__":elect_init()  # 初始化继电器monitor_log()  # 开始监控日志文件

实验现象

执行脚本后,如果文件不存在会直接打印文件不存在,找到对应关键字和执行相关操作都会有时间打印。
在这里插入图片描述

注意

mobxterm等其他串口工具可以实现自动保存日志,但是日志不会再次刷新,python脚本中需要检测文件编辑时间去再次打开文件获取最新串口数据

http://www.hengruixuexiao.com/news/22396.html

相关文章:

  • 建筑网格布是用什么材料杭州seo平台
  • 大型网站开发java网站搭建一般要多少钱
  • 德阳做网站的网站推广专家
  • 河北省网站备案步骤武汉网站搜索引擎优化
  • 做网站登录的需求分析太原最新情况
  • 天元建设集团有限公司张桂玉丑闻事件seo服务合同
  • 万远翔网站建设百度网站官网
  • 个人做网站多少钱软文有哪些
  • 开发公司网签合同条件seo是什么职位简称
  • 论坛打赏网站开发搜什么关键词比较刺激
  • 深圳都信建设监理有限公司网站产品品牌策划方案
  • 山东省荣成市建设局网站seo关键词排名优化系统
  • 校际凡科平台官网seo是什么缩写
  • 网站静态页模板快速优化关键词排名
  • 上海网站建设免微博推广方法有哪些
  • 深圳公司设计网站百度网站站长工具
  • 郑州市网站建设公司收录提交入口
  • 大连中小网站建设公司百度网站ip地址
  • 广州建网站兴田德润信任营销策划与运营团队
  • 西宁网站开发公司好用的搜索引擎有哪些
  • 有域名如何建网站app开发平台开发
  • 辽阳网站推广外贸独立站怎么建站
  • 金堂企业网站建设百度推广一天烧几千
  • 公司怎么做网站需要多少钱设计师必备的6个网站
  • wordpress变404seo优化好做吗
  • web网站开发软件百度云网页版入口
  • 什么样的网站容易做seo东莞网站建设推广哪家好
  • 网站建设怎么谈网络舆情管理
  • 优化网站佛山厂商常见的关键词
  • 美食网站建设的意义自媒体运营主要做什么