90 @return flag indicating a timeout |
90 @return flag indicating a timeout |
91 @@rtype bool |
91 @@rtype bool |
92 """ |
92 """ |
93 return self.__timedOut |
93 return self.__timedOut |
94 |
94 |
95 def readUntil(self, expected=b"\n", size=None): |
95 def readUntil(self, expected=b"\n", size=None, timeout=0): |
96 r""" |
96 r""" |
97 Public method to read data until an expected sequence is found |
97 Public method to read data until an expected sequence is found |
98 (default: \n) or a specific size is exceeded. |
98 (default: \n) or a specific size is exceeded. |
99 |
99 |
100 @param expected expected bytes sequence |
100 @param expected expected bytes sequence |
101 @type bytes |
101 @type bytes |
102 @param size maximum data to be read |
102 @param size maximum data to be read (defaults to None) |
103 @type int |
103 @type int (optional) |
|
104 @param timeout timeout in milliseconds (0 for configured default) |
|
105 (defaults to 0) |
|
106 @type int (optional) |
104 @return bytes read from the device including the expected sequence |
107 @return bytes read from the device including the expected sequence |
105 @rtype bytes |
108 @rtype bytes |
106 """ |
109 """ |
107 data = bytearray() |
110 data = bytearray() |
108 self.__timedOut = False |
111 self.__timedOut = False |
|
112 |
|
113 if timeout == 0: |
|
114 timeout = self.__timeout |
109 |
115 |
110 t = QTime.currentTime() |
116 t = QTime.currentTime() |
111 while True: |
117 while True: |
112 QCoreApplication.processEvents( |
118 QCoreApplication.processEvents( |
113 QEventLoop.ProcessEventsFlag.ExcludeUserInputEvents |
119 QEventLoop.ProcessEventsFlag.ExcludeUserInputEvents |