eric6/MicroPython/MicroPythonSerialPort.py

branch
micropython
changeset 7077
3b7475b7a1ef
parent 7070
3368ce0e7879
child 7082
ec199ef0cfc6
equal deleted inserted replaced
7070:3368ce0e7879 7077:3b7475b7a1ef
8 MicroPython devices. 8 MicroPython devices.
9 """ 9 """
10 10
11 from __future__ import unicode_literals 11 from __future__ import unicode_literals
12 12
13 from PyQt5.QtCore import QIODevice, QTime 13 from PyQt5.QtCore import QIODevice, QTime, QCoreApplication
14 from PyQt5.QtSerialPort import QSerialPort 14 from PyQt5.QtSerialPort import QSerialPort
15 15
16 16
17 class MicroPythonSerialPort(QSerialPort): 17 class MicroPythonSerialPort(QSerialPort):
18 """ 18 """
67 67
68 def closeSerialLink(self): 68 def closeSerialLink(self):
69 """ 69 """
70 Public method to close the open serial connection. 70 Public method to close the open serial connection.
71 """ 71 """
72 if self.__connceted: 72 if self.__connected:
73 self.close() 73 self.close()
74 74
75 self.__connected = False 75 self.__connected = False
76 76
77 def isConnected(self): 77 def isConnected(self):
93 @param size maximum data to be read 93 @param size maximum data to be read
94 @type int 94 @type int
95 @return bytes read from the device including the expected sequence 95 @return bytes read from the device including the expected sequence
96 @rtype bytes 96 @rtype bytes
97 """ 97 """
98 from PyQt5.QtCore import QCoreApplication, QEventLoop
99 data = bytearray() 98 data = bytearray()
100 99
101 t = QTime() 100 t = QTime()
102 t.start() 101 t.start()
103 while True: 102 while True:
104 # TODO: check if this is still needed when used with a QThread 103 QCoreApplication.processEvents()
105 QCoreApplication.processEvents(QEventLoop.ExcludeUserInputEvents)
106 ## if self.waitForReadyRead(self.__timeout):
107 c = bytes(self.read(1)) 104 c = bytes(self.read(1))
108 if c: 105 if c:
109 data += c 106 data += c
110 if data.endswith(expected): 107 if data.endswith(expected):
111 break 108 break
113 break 110 break
114 # else: 111 # else:
115 # break 112 # break
116 if t.elapsed() > self.__timeout: 113 if t.elapsed() > self.__timeout:
117 break 114 break
118 ## else:
119 ## break
120 115
121 return bytes(data) 116 return bytes(data)

eric ide

mercurial