Skip to content

Commit 3b47d42

Browse files
authored
Add socketcan parameter to ignore CAN error frames (#1128)
1 parent 5b5bcc2 commit 3b47d42

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

can/interfaces/socketcan/socketcan.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,7 @@ def __init__(
610610
local_loopback: bool = True,
611611
fd: bool = False,
612612
can_filters: Optional[CanFilters] = None,
613+
ignore_rx_error_frames=False,
613614
**kwargs,
614615
) -> None:
615616
"""Creates a new socketcan bus.
@@ -639,6 +640,8 @@ def __init__(
639640
If CAN-FD frames should be supported.
640641
:param can_filters:
641642
See :meth:`can.BusABC.set_filters`.
643+
:param ignore_rx_error_frames:
644+
If incoming error frames should be discarded.
642645
"""
643646
self.socket = create_socket()
644647
self.channel = channel
@@ -671,11 +674,12 @@ def __init__(
671674
except socket.error as error:
672675
log.error("Could not enable CAN-FD frames (%s)", error)
673676

674-
# enable error frames
675-
try:
676-
self.socket.setsockopt(SOL_CAN_RAW, CAN_RAW_ERR_FILTER, 0x1FFFFFFF)
677-
except socket.error as error:
678-
log.error("Could not enable error frames (%s)", error)
677+
if not ignore_rx_error_frames:
678+
# enable error frames
679+
try:
680+
self.socket.setsockopt(SOL_CAN_RAW, CAN_RAW_ERR_FILTER, 0x1FFFFFFF)
681+
except socket.error as error:
682+
log.error("Could not enable error frames (%s)", error)
679683

680684
# enable nanosecond resolution timestamping
681685
# we can always do this since

0 commit comments

Comments
 (0)