通过两个进程分别读写串口,并把发送与接收到的内容记录在blog中,收到q时程序结束并退出
import threading,time
import serial
import string
class SerThread:
def __init__(self, Port=0):
#初始化串口、blog文件名称
self.my_serial = serial.Serial()
self.my_serial.port=Port
self.my_serial.baudrate = 9600
self.my_serial.timeout = 1
self.alive = False
self.waitEnd = None
fname=time.strftime("%Y%m%d")#blog名称为当前时间
self.rfname='r'+fname #接收blog名称
self.sfname='s'+fname #发送blog名称
self.thread_read= None
self.thread_send=None
def waiting(self):
# 等待event停止标志
if not self.waitEnd is None:
self.waitEnd.wait()
def start(self):
#开串口以及blog文件
self.rfile=open(self.rfname,