#!/usr/bin/env python3 # -*- coding: utf-8 -*- """控制台快速侦察:打开串口读取若干秒,观察设备状态与日志格式""" import sys import time import serial port = sys.argv[1] if len(sys.argv) > 1 else "COM3" secs = float(sys.argv[2]) if len(sys.argv) > 2 else 8.0 s = serial.Serial(port=port, baudrate=115200, bytesize=8, parity="N", stopbits=1, timeout=0.05) print("opened %s @115200, reading %.1fs ..." % (port, secs)) buf = b"" t0 = time.time() while time.time() - t0 < secs: n = s.in_waiting if n: buf += s.read(n) else: time.sleep(0.05) s.close() text = buf.decode("utf-8", errors="replace") print("=== bytes: %d ===" % len(buf)) print(text[:4000]) if len(text) > 4000: print("...(truncated)...") print(text[-1500:])