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 """ |
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 |