src/eric7/MicroPython/MicroPythonSerialPort.py

branch
mpy_network
changeset 9775
c6806d24468b
parent 9653
e67609152c5e
child 10229
e50bbf250343
equal deleted inserted replaced
9774:c7b712056146 9775:c6806d24468b
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
117 data += c 123 data += c
118 if data.endswith(expected): 124 if data.endswith(expected):
119 break 125 break
120 if size is not None and len(data) >= size: 126 if size is not None and len(data) >= size:
121 break 127 break
122 if t.msecsTo(QTime.currentTime()) > self.__timeout: 128 if t.msecsTo(QTime.currentTime()) > timeout:
123 self.__timedOut = True 129 self.__timedOut = True
124 break 130 break
125 131
126 return bytes(data) 132 return bytes(data)

eric ide

mercurial