File tree 1 file changed +25
-0
lines changed
1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -293,6 +293,31 @@ def fileno(self) -> int:
293
293
except Exception as exception :
294
294
raise CanOperationError ("Cannot fetch fileno" ) from exception
295
295
296
+ def _read (self , timeout : Optional [float ]) -> Optional [str ]:
297
+ _timeout = serial .Timeout (timeout )
298
+
299
+ with error_check ("Could not read from serial device" ):
300
+ while True :
301
+ # Due to accessing `serialPortOrig.in_waiting` too often will reduce the performance.
302
+ # We read the `serialPortOrig.in_waiting` only once here.
303
+ in_waiting = self .serialPortOrig .in_waiting
304
+ for _ in range (max (1 , in_waiting )):
305
+ new_byte = self .serialPortOrig .read (size = 1 )
306
+ if new_byte :
307
+ self ._buffer .extend (new_byte )
308
+ else :
309
+ break
310
+
311
+ if new_byte in (self ._ERROR , self ._OK ):
312
+ string = self ._buffer .decode ()
313
+ self ._buffer .clear ()
314
+ return string
315
+
316
+ if _timeout .expired ():
317
+ break
318
+
319
+ return None
320
+
296
321
def get_version (self , timeout : Optional [float ]) -> Tuple [Optional [int ], Optional [int ]]:
297
322
"""Get HW and SW version of the slcan interface.
298
323
You can’t perform that action at this time.
0 commit comments