Skip to content

Commit 7302127

Browse files
authored
Fix for #1849 (PCAN fails when PCAN_ERROR_ILLDATA is read via ReadFD) (#1850)
* When there is an invalid frame on CAN bus (in our case CAN FD), PCAN first reports result PCAN_ERROR_ILLDATA and then it send the error frame. If the PCAN_ERROR_ILLDATA is not ignored, python-can throws an exception. This fix add the ignore on the PCAN_ERROR_ILLDATA. * Fix for ruff error `can/interfaces/pcan/pcan.py:5:1: I001 [*] Import block is un-sorted or un-formatted` Added comment explaining why to ignore the PCAN_ERROR_ILLDATA.
1 parent c712131 commit 7302127

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

can/interfaces/pcan/pcan.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
PCAN_DICT_STATUS,
4444
PCAN_ERROR_BUSHEAVY,
4545
PCAN_ERROR_BUSLIGHT,
46+
PCAN_ERROR_ILLDATA,
4647
PCAN_ERROR_OK,
4748
PCAN_ERROR_QRCVEMPTY,
4849
PCAN_FD_PARAMETER_LIST,
@@ -555,6 +556,12 @@ def _recv_internal(
555556
elif result & (PCAN_ERROR_BUSLIGHT | PCAN_ERROR_BUSHEAVY):
556557
log.warning(self._get_formatted_error(result))
557558

559+
elif result == PCAN_ERROR_ILLDATA:
560+
# When there is an invalid frame on CAN bus (in our case CAN FD), PCAN first reports result PCAN_ERROR_ILLDATA
561+
# and then it sends the error frame. If the PCAN_ERROR_ILLDATA is not ignored, python-can throws an exception.
562+
# So we ignore any PCAN_ERROR_ILLDATA results here.
563+
pass
564+
558565
else:
559566
raise PcanCanOperationError(self._get_formatted_error(result))
560567

0 commit comments

Comments
 (0)