@@ -265,7 +265,13 @@ def _recv_internal(self, timeout):
265265
266266 if rx_byte_1 and ord (rx_byte_1 ) == 0xAA :
267267 try :
268- rx_byte_2 = ord (self .ser .read ())
268+ if self .ser .in_waiting >= 1 :
269+ rx_byte_2_opt = self .ser .read ()
270+ else :
271+ # Should not get to this line
272+ logger .debug ("received 0xAA, then serial stopped" )
273+ rx_byte_2_opt = 0x00
274+ rx_byte_2 = ord (rx_byte_2_opt )
269275
270276 time_stamp = time ()
271277 if rx_byte_2 == 0x55 :
@@ -286,7 +292,21 @@ def _recv_internal(self, timeout):
286292 arb_id = (struct .unpack ("<H" , s_3_4 ))[0 ]
287293
288294 data = bytearray (self .ser .read (length ))
289- end_packet = ord (self .ser .read ())
295+
296+ if self .ser .in_waiting >= 1 :
297+ end_packet_opt = self .ser .read ()
298+ else :
299+ logger .debug ("no end byte?" )
300+ # Seems to be a bug in the seeedstudio-dongle, rarely
301+ # the end-byte is missing. Rarely: ~0.1% of the packets?
302+ # The communication works otherwise fine, no bad data
303+ # packets have been observed. Probably the underlying
304+ # usb-driver serves as a good protection.
305+ # No bad packets (corrupted data), despite this one
306+ # end-byte has been observed.
307+ # To ensure no data is lost, we fake an end-byte here.
308+ end_packet_opt = "U"
309+ end_packet = ord (end_packet_opt )
290310 if end_packet == 0x55 :
291311 msg = Message (
292312 timestamp = time_stamp ,
0 commit comments