#!/usr/bin/python#-*-coding: utf-8 -*-
importserialimportthreadingimportbinasciifrom datetime importdatetimeimportstructimportcsvclassSerialPort:def __init__(self, port, buand):
self.port=serial.Serial(port, buand)
self.port.close()if notself.port.isOpen():
self.port.open()defport_open(self):if notself.port.isOpen():
self.port.open()defport_close(self):
self.port.close()defsend_data(self):
self.port.write('')defread_data(self):globalis_exitglobaldata_byteswhile notis_exit:
count=self.port.inWaiting()if count >0:
rec_str=self.port.read(count)
data_bytes=data_bytes+rec_str#print('当前数据接收总字节数:'+str(len(data_bytes))+' 本次接收字节数:'+str(len(rec_str)))
#print(str(datetime.now()),':',binascii.b2a_hex(rec_str))
serialPort= 'COM6' #串口
baudRate = 115200 #波