Skip to content

Commit

Permalink
Fix for hardbyte#1849 (PCAN fails when PCAN_ERROR_ILLDATA is read via…
Browse files Browse the repository at this point in the history
… ReadFD) (hardbyte#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.
  • Loading branch information
bures authored and SWolfSchunk committed Sep 9, 2024
1 parent 56262ea commit efb0f94
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions can/interfaces/pcan/pcan.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
PCAN_DICT_STATUS,
PCAN_ERROR_BUSHEAVY,
PCAN_ERROR_BUSLIGHT,
PCAN_ERROR_ILLDATA,
PCAN_ERROR_OK,
PCAN_ERROR_QRCVEMPTY,
PCAN_FD_PARAMETER_LIST,
Expand Down Expand Up @@ -555,6 +556,12 @@ def _recv_internal(
elif result & (PCAN_ERROR_BUSLIGHT | PCAN_ERROR_BUSHEAVY):
log.warning(self._get_formatted_error(result))

elif result == PCAN_ERROR_ILLDATA:
# When there is an invalid frame on CAN bus (in our case CAN FD), PCAN first reports result PCAN_ERROR_ILLDATA
# and then it sends the error frame. If the PCAN_ERROR_ILLDATA is not ignored, python-can throws an exception.
# So we ignore any PCAN_ERROR_ILLDATA results here.
pass

else:
raise PcanCanOperationError(self._get_formatted_error(result))

Expand Down

0 comments on commit efb0f94

Please sign in to comment.