Skip to content

Enable echo frames in PCAN driver if receive_own_messages is set #1723

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 20, 2024
Merged
Changes from 2 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
13 changes: 13 additions & 0 deletions can/interfaces/pcan/pcan.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
FEATURE_FD_CAPABLE,
IS_LINUX,
IS_WINDOWS,
PCAN_ALLOW_ECHO_FRAMES,
PCAN_ALLOW_ERROR_FRAMES,
PCAN_API_VERSION,
PCAN_ATTACHED_CHANNELS,
Expand Down Expand Up @@ -120,6 +121,7 @@ def __init__(
state: BusState = BusState.ACTIVE,
timing: Optional[Union[BitTiming, BitTimingFd]] = None,
bitrate: int = 500000,
receive_own_messages: bool = False,
**kwargs: Any,
):
"""A PCAN USB interface to CAN.
Expand Down Expand Up @@ -162,6 +164,9 @@ def __init__(
Default is 500 kbit/s.
Ignored if using CanFD.

:param receive_own_messages:
Enable self-reception of sent messages.

:param bool fd:
Should the Bus be initialized in CAN-FD mode.

Expand Down Expand Up @@ -316,6 +321,14 @@ def __init__(
"Ignoring error. PCAN_ALLOW_ERROR_FRAMES is still unsupported by OSX Library PCANUSB v0.11.2"
)

if receive_own_messages:
result = self.m_objPCANBasic.SetValue(
self.m_PcanHandle, PCAN_ALLOW_ECHO_FRAMES, PCAN_PARAMETER_ON
)

if result != PCAN_ERROR_OK:
raise PcanCanInitializationError(self._get_formatted_error(result))

if kwargs.get("auto_reset", False):
result = self.m_objPCANBasic.SetValue(
self.m_PcanHandle, PCAN_BUSOFF_AUTORESET, PCAN_PARAMETER_ON
Expand Down