代码拉取完成,页面将自动刷新
同步操作将从 Neeil/DreamSerial 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
# -*- coding: utf-8 -*-
"""
Created on Tue Aug 25 15:46:33 2015
@author: fg086897
"""
import threading
from time import sleep
from serial import Serial
import logging
from PyQt5.QtCore import pyqtSignal, QObject
logger = logging.getLogger('main.DsSerial')
class DsSerial(QObject, threading.Thread):
received = pyqtSignal(bytes)
def __init__(self):
super(DsSerial, self).__init__()
# threading.Thread.__init__(self)
self.__terminate = False
logger.info('DsSerial Logger Start')
@staticmethod
def searchSerialPort():
''' Search the valid serial port '''
ports = []
for i in range(100):
port = 'COM' + str(i + 1)
try:
s = Serial(port)
if s.isOpen():
s.close()
ports.append(port)
logger.info("Found :" + port)
except Exception as msg:
pass
return ports
def open(self, settings):
try:
self.serial = Serial(settings['port'], settings['baud'],
settings['bytesize'], settings['parity'],
settings['stopbits'],settings['timeout'])
self.serial.flushInput()
self.serial.flushOutput()
except Exception as msg:
logger.info('Port Open Failed :' + msg)
logger.info('Port Opened Successful')
return True, 'Successful'
def getPort(self):
print(self.serial)
def terminate(self):
self.__terminate = True;
def send(self, data):
if self.serial.isOpen():
try:
self.serial.write(data)
except Exception as msg:
logger.info("Port write failed :" + msg)
else:
logger.error('Port Not Open')
def __recv(self):
data, quit = None, False
while True:
if self.__terminate:
break
data = self.serial.read(1)
if data == b'':
continue
while True:
n = self.serial.inWaiting()
if n > 0 :
data = '%s%s' % (data, self.serial.read(n))
sleep(0.02)
else:
quit = True
break
if quit:
break
return data
def close(self):
if self.serial.isOpen():
self.serial.close()
def run(self):
while 1:
data = self.__recv()
if not data:
break
self.received.emit(data)
self.serial.close()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。