Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions can/interfaces/seeedstudio/seeedstudio.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,9 @@ def _recv_internal(self, timeout):

if rx_byte_1 and ord(rx_byte_1) == 0xAA:
try:
rx_byte_2 = ord(self.ser.read())
if self.ser.in_waiting >= 1:
rx_byte_2_opt = self.ser.read()
rx_byte_2 = ord(rx_byte_2_opt)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you rebase onto the latest main branch, pylint will complain about possible-use-before-assignment here.
if in_waiting returns 0, this will raise an error.


time_stamp = time()
if rx_byte_2 == 0x55:
Expand All @@ -294,7 +296,21 @@ def _recv_internal(self, timeout):
arb_id = (struct.unpack("<H", s_3_4))[0]

data = bytearray(self.ser.read(length))
end_packet = ord(self.ser.read())

if self.ser.in_waiting >= 1:
end_packet_opt = self.ser.read()
else:
logger.debug("no end byte?")
# Seems to be a bug in the seeedstudio-dongle, rarely
# the end-byte is missing. Rarely: ~0.1% of the packets?
# The communication works otherwise fine, no bad data
# packets have been observed. Probably the underlying
# usb-driver serves as a good protection.
# No bad packets (corrupted data), despite this one
# end-byte has been observed.
# To ensure no data is lost, we fake an end-byte here.
end_packet_opt = "U"
end_packet = ord(end_packet_opt)
if end_packet == 0x55:
msg = Message(
timestamp=time_stamp,
Expand Down