@@ -273,7 +273,9 @@ def _recv_internal(self, timeout):
273273
274274 if rx_byte_1 and ord (rx_byte_1 ) == 0xAA :
275275 try :
276- rx_byte_2 = ord (self .ser .read ())
276+ if self .ser .in_waiting >= 1 :
277+ rx_byte_2_opt = self .ser .read ()
278+ rx_byte_2 = ord (rx_byte_2_opt )
277279
278280 time_stamp = time ()
279281 if rx_byte_2 == 0x55 :
@@ -294,7 +296,21 @@ def _recv_internal(self, timeout):
294296 arb_id = (struct .unpack ("<H" , s_3_4 ))[0 ]
295297
296298 data = bytearray (self .ser .read (length ))
297- end_packet = ord (self .ser .read ())
299+
300+ if self .ser .in_waiting >= 1 :
301+ end_packet_opt = self .ser .read ()
302+ else :
303+ logger .debug ("no end byte?" )
304+ # Seems to be a bug in the seeedstudio-dongle, rarely
305+ # the end-byte is missing. Rarely: ~0.1% of the packets?
306+ # The communication works otherwise fine, no bad data
307+ # packets have been observed. Probably the underlying
308+ # usb-driver serves as a good protection.
309+ # No bad packets (corrupted data), despite this one
310+ # end-byte has been observed.
311+ # To ensure no data is lost, we fake an end-byte here.
312+ end_packet_opt = "U"
313+ end_packet = ord (end_packet_opt )
298314 if end_packet == 0x55 :
299315 msg = Message (
300316 timestamp = time_stamp ,
0 commit comments