add silent mode support for vector by cperkulator · Pull Request #1764 · hardbyte/python-can
Expand Up
@@ -104,6 +104,7 @@ def __init__(
sjw_dbr: int = 2,
tseg1_dbr: int = 6,
tseg2_dbr: int = 3,
listen_only: Optional[bool] = False,
**kwargs: Any,
) -> None:
"""
Expand Down
Expand Up
@@ -157,6 +158,8 @@ def __init__(
Bus timing value tseg1 (data)
:param tseg2_dbr:
Bus timing value tseg2 (data)
:param listen_only:
if the bus should be set to listen only mode.
:raise ~can.exceptions.CanInterfaceNotImplementedError: If the current operating system is not supported or the driver could not be loaded. Expand Down Expand Up @@ -205,6 +208,8 @@ def __init__( self.index_to_channel: Dict[int, int] = {} self._can_protocol = CanProtocol.CAN_FD if is_fd else CanProtocol.CAN_20
self._listen_only = listen_only
for channel in self.channels: if ( len(self.channels) == 1 Expand Down Expand Up @@ -232,7 +237,7 @@ def __init__(
permission_mask = xlclass.XLaccess() # Set mask to request channel init permission if needed if bitrate or fd or timing: if bitrate or fd or timing or self._listen_only: permission_mask.value = self.mask
interface_version = ( Expand Down Expand Up @@ -311,6 +316,9 @@ def __init__( if assert_timing: self._check_can_settings(channel_mask=self.mask, bitrate=bitrate)
if self._listen_only: self._set_output_mode(channel_mask=self.mask, listen_only=True)
# Enable/disable TX receipts tx_receipts = 1 if receive_own_messages else 0 self.xldriver.xlCanSetChannelMode(self.port_handle, self.mask, tx_receipts, 0) Expand Down Expand Up @@ -445,6 +453,28 @@ def _read_bus_params( f"Channel configuration for channel {channel} not found." )
def _set_output_mode(self, channel_mask: int, listen_only: bool) -> None: # set parameters for channels with init access channel_mask = channel_mask & self.permission_mask
if channel_mask: if listen_only: self.xldriver.xlCanSetChannelOutput( self.port_handle, channel_mask, xldefine.XL_OutputMode.XL_OUTPUT_MODE_SILENT, ) else: self.xldriver.xlCanSetChannelOutput( self.port_handle, channel_mask, xldefine.XL_OutputMode.XL_OUTPUT_MODE_NORMAL, )
LOG.info("xlCanSetChannelOutput: listen_only=%u", listen_only) else: LOG.warning("No channels with init access to set listen only mode")
def _set_bitrate(self, channel_mask: int, bitrate: int) -> None: # set parameters for channels with init access channel_mask = channel_mask & self.permission_mask Expand Down Expand Up @@ -643,9 +673,11 @@ def _apply_filters(self, filters: Optional[CanFilters]) -> None: self.mask, can_filter["can_id"], can_filter["can_mask"], xldefine.XL_AcceptanceFilter.XL_CAN_EXT if can_filter.get("extended") else xldefine.XL_AcceptanceFilter.XL_CAN_STD, ( xldefine.XL_AcceptanceFilter.XL_CAN_EXT if can_filter.get("extended") else xldefine.XL_AcceptanceFilter.XL_CAN_STD ), ) except VectorOperationError as exception: LOG.warning("Could not set filters: %s", exception) Expand Down
:raise ~can.exceptions.CanInterfaceNotImplementedError: If the current operating system is not supported or the driver could not be loaded. Expand Down Expand Up @@ -205,6 +208,8 @@ def __init__( self.index_to_channel: Dict[int, int] = {} self._can_protocol = CanProtocol.CAN_FD if is_fd else CanProtocol.CAN_20
self._listen_only = listen_only
for channel in self.channels: if ( len(self.channels) == 1 Expand Down Expand Up @@ -232,7 +237,7 @@ def __init__(
permission_mask = xlclass.XLaccess() # Set mask to request channel init permission if needed if bitrate or fd or timing: if bitrate or fd or timing or self._listen_only: permission_mask.value = self.mask
interface_version = ( Expand Down Expand Up @@ -311,6 +316,9 @@ def __init__( if assert_timing: self._check_can_settings(channel_mask=self.mask, bitrate=bitrate)
if self._listen_only: self._set_output_mode(channel_mask=self.mask, listen_only=True)
# Enable/disable TX receipts tx_receipts = 1 if receive_own_messages else 0 self.xldriver.xlCanSetChannelMode(self.port_handle, self.mask, tx_receipts, 0) Expand Down Expand Up @@ -445,6 +453,28 @@ def _read_bus_params( f"Channel configuration for channel {channel} not found." )
def _set_output_mode(self, channel_mask: int, listen_only: bool) -> None: # set parameters for channels with init access channel_mask = channel_mask & self.permission_mask
if channel_mask: if listen_only: self.xldriver.xlCanSetChannelOutput( self.port_handle, channel_mask, xldefine.XL_OutputMode.XL_OUTPUT_MODE_SILENT, ) else: self.xldriver.xlCanSetChannelOutput( self.port_handle, channel_mask, xldefine.XL_OutputMode.XL_OUTPUT_MODE_NORMAL, )
LOG.info("xlCanSetChannelOutput: listen_only=%u", listen_only) else: LOG.warning("No channels with init access to set listen only mode")
def _set_bitrate(self, channel_mask: int, bitrate: int) -> None: # set parameters for channels with init access channel_mask = channel_mask & self.permission_mask Expand Down Expand Up @@ -643,9 +673,11 @@ def _apply_filters(self, filters: Optional[CanFilters]) -> None: self.mask, can_filter["can_id"], can_filter["can_mask"], xldefine.XL_AcceptanceFilter.XL_CAN_EXT if can_filter.get("extended") else xldefine.XL_AcceptanceFilter.XL_CAN_STD, ( xldefine.XL_AcceptanceFilter.XL_CAN_EXT if can_filter.get("extended") else xldefine.XL_AcceptanceFilter.XL_CAN_STD ), ) except VectorOperationError as exception: LOG.warning("Could not set filters: %s", exception) Expand Down