python串口自动测试
文章目录
安装使用 pip install pyserial
打开和退出信号
com = serial.Serial("com15", 115200, timeout=0.5)
def sig_handler(sig, frame):
com.close()
exit(0)
signal.signal(signal.SIGTERM, sig_handler)
signal.signal(signal.SIGINT, sig_handler)
try:
com.open()
except:
com.close()
com.open()读取一行输出
try:
readline = str(com.readline(), encoding = "utf8")
except:
continue读取指定信息时候发送指定命令
try:
if re.findall(r'xxx readline, flags=0):
com.write(bytes("\r\nreboot\r\n", encoding = "utf8"))
except:
print("some errr....")
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论