|
26 | 26 | FEATURE_FD_CAPABLE, |
27 | 27 | IS_LINUX, |
28 | 28 | IS_WINDOWS, |
| 29 | + PCAN_ALLOW_ECHO_FRAMES, |
29 | 30 | PCAN_ALLOW_ERROR_FRAMES, |
30 | 31 | PCAN_API_VERSION, |
31 | 32 | PCAN_ATTACHED_CHANNELS, |
|
47 | 48 | PCAN_LANBUS1, |
48 | 49 | PCAN_LISTEN_ONLY, |
49 | 50 | PCAN_MESSAGE_BRS, |
| 51 | + PCAN_MESSAGE_ECHO, |
50 | 52 | PCAN_MESSAGE_ERRFRAME, |
51 | 53 | PCAN_MESSAGE_ESI, |
52 | 54 | PCAN_MESSAGE_EXTENDED, |
@@ -120,6 +122,7 @@ def __init__( |
120 | 122 | state: BusState = BusState.ACTIVE, |
121 | 123 | timing: Optional[Union[BitTiming, BitTimingFd]] = None, |
122 | 124 | bitrate: int = 500000, |
| 125 | + receive_own_messages: bool = False, |
123 | 126 | **kwargs: Any, |
124 | 127 | ): |
125 | 128 | """A PCAN USB interface to CAN. |
@@ -162,6 +165,9 @@ def __init__( |
162 | 165 | Default is 500 kbit/s. |
163 | 166 | Ignored if using CanFD. |
164 | 167 |
|
| 168 | + :param receive_own_messages: |
| 169 | + Enable self-reception of sent messages. |
| 170 | +
|
165 | 171 | :param bool fd: |
166 | 172 | Should the Bus be initialized in CAN-FD mode. |
167 | 173 |
|
@@ -316,6 +322,14 @@ def __init__( |
316 | 322 | "Ignoring error. PCAN_ALLOW_ERROR_FRAMES is still unsupported by OSX Library PCANUSB v0.11.2" |
317 | 323 | ) |
318 | 324 |
|
| 325 | + if receive_own_messages: |
| 326 | + result = self.m_objPCANBasic.SetValue( |
| 327 | + self.m_PcanHandle, PCAN_ALLOW_ECHO_FRAMES, PCAN_PARAMETER_ON |
| 328 | + ) |
| 329 | + |
| 330 | + if result != PCAN_ERROR_OK: |
| 331 | + raise PcanCanInitializationError(self._get_formatted_error(result)) |
| 332 | + |
319 | 333 | if kwargs.get("auto_reset", False): |
320 | 334 | result = self.m_objPCANBasic.SetValue( |
321 | 335 | self.m_PcanHandle, PCAN_BUSOFF_AUTORESET, PCAN_PARAMETER_ON |
@@ -548,6 +562,7 @@ def _recv_internal( |
548 | 562 | is_extended_id = bool(pcan_msg.MSGTYPE & PCAN_MESSAGE_EXTENDED.value) |
549 | 563 | is_remote_frame = bool(pcan_msg.MSGTYPE & PCAN_MESSAGE_RTR.value) |
550 | 564 | is_fd = bool(pcan_msg.MSGTYPE & PCAN_MESSAGE_FD.value) |
| 565 | + is_rx = not bool(pcan_msg.MSGTYPE & PCAN_MESSAGE_ECHO.value) |
551 | 566 | bitrate_switch = bool(pcan_msg.MSGTYPE & PCAN_MESSAGE_BRS.value) |
552 | 567 | error_state_indicator = bool(pcan_msg.MSGTYPE & PCAN_MESSAGE_ESI.value) |
553 | 568 | is_error_frame = bool(pcan_msg.MSGTYPE & PCAN_MESSAGE_ERRFRAME.value) |
@@ -575,6 +590,7 @@ def _recv_internal( |
575 | 590 | dlc=dlc, |
576 | 591 | data=pcan_msg.DATA[:dlc], |
577 | 592 | is_fd=is_fd, |
| 593 | + is_rx=is_rx, |
578 | 594 | bitrate_switch=bitrate_switch, |
579 | 595 | error_state_indicator=error_state_indicator, |
580 | 596 | ) |
|
0 commit comments