Function:控制继电器上下电,上电后adb登录,copy配置文件
import serial import time import datetime import subprocess import os def append_to_txt(file_path, content): if os.path.exists(file_path): with open(file_path, 'a') as file: # 使用 'a' 模式打开文件进行追加 file.write(content + '\n') # 追加内容,并换行 else: with open(file_path, 'w') as file: # 如果文件不存在,使用 'w' 模式创建文件 file.write(content + '\n') # 写入内容,并换行 def execute_adb_command(command): try: # 执行adb命令 subprocess.run(["adb", "shell", command], check=True) except subprocess.CalledProcessError as e: print(f"Error executing adb command: {e}") def send_data(port, baudrate, timeout): ser = None try: # 打开串口 ser = serial.Serial(port, baudrate, timeout=timeout) countNum = 65; intervalTime = 60 # 时间间隔 countTotal = 300 # 循环次数 while countNum test/backup_config_$(date +\"%Y%m%d_%H%M%S\").txt") countNum += 1 now = datetime.datetime.now() print("Save Done ===> countNum=", countNum, "/", countTotal, " kl30onTime[s]=", kl30onTime," timestamp=", now) # 将当前时间保存到本地txt文件 file_path = 'E:\Testlog\\timeStamp20240515.txt' content_to_append = f'Save Done ===> countNum={countNum}/{countTotal}, kl30onTime[s]={kl30onTime}, timestamp={now}' append_to_txt(file_path, content_to_append) # with open('E:\Testlog\\timeStamp.txt', 'a') as file: # file.write(f'Save Successfully, Count={count}, kl30onTime={kl30onTime}, timestamp={now}' + '\n') time.sleep(10) # data = bytes([0x00, 0x01, 0xFF]) # 代表ch1关闭 ser.write(data) # #print("ch1 Close") time.sleep(10) except Exception as e: print("Exception occurred:", e) finally: # 关闭串口 if ser: ser.close() def main(): # 调用send_data()方法,并将串口号转换为字符串 send_data('COM1', 9600, 10) if __name__ == '__main__': print("=============Start==============") main() print("==============End===============")
(图片来源网络,侵删)
文章版权声明:除非注明,否则均为主机测评原创文章,转载或复制请以超链接形式并注明出处。