Skip to content

Activate channels after CAN filters were applied #1796

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 1 commit into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 7 additions & 4 deletions can/interfaces/kvaser/canlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,16 +552,13 @@ def __init__(
else:
flags_ = flags
self._write_handle = canOpenChannel(channel, flags_)
canBusOn(self._read_handle)

can_driver_mode = (
canstat.canDRIVER_SILENT
if driver_mode == DRIVER_MODE_SILENT
else canstat.canDRIVER_NORMAL
)
canSetBusOutputControl(self._write_handle, can_driver_mode)
log.debug("Going bus on TX handle")
canBusOn(self._write_handle)

timer = ctypes.c_uint(0)
try:
Expand All @@ -587,6 +584,12 @@ def __init__(
**kwargs,
)

# activate channel after CAN filters were applied
log.debug("Go on bus")
if not self.single_handle:
canBusOn(self._read_handle)
canBusOn(self._write_handle)

def _apply_filters(self, filters):
if filters and len(filters) == 1:
can_id = filters[0]["can_id"]
Expand All @@ -610,7 +613,7 @@ def _apply_filters(self, filters):
for extended in (0, 1):
canSetAcceptanceFilter(handle, 0, 0, extended)
except (NotImplementedError, CANLIBError) as e:
log.error("An error occured while disabling filtering: %s", e)
log.error("An error occurred while disabling filtering: %s", e)

def flush_tx_buffer(self):
"""Wipeout the transmit buffer on the Kvaser."""
Expand Down
17 changes: 9 additions & 8 deletions can/interfaces/vector/canlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,14 +329,6 @@ def __init__(
else:
LOG.info("Install pywin32 to avoid polling")

try:
self.xldriver.xlActivateChannel(
self.port_handle, self.mask, xldefine.XL_BusTypes.XL_BUS_TYPE_CAN, 0
)
except VectorOperationError as error:
self.shutdown()
raise VectorInitializationError.from_generic(error) from None

# Calculate time offset for absolute timestamps
offset = xlclass.XLuint64()
try:
Expand Down Expand Up @@ -366,6 +358,15 @@ def __init__(
**kwargs,
)

# activate channels after CAN filters were applied
try:
self.xldriver.xlActivateChannel(
self.port_handle, self.mask, xldefine.XL_BusTypes.XL_BUS_TYPE_CAN, 0
)
except VectorOperationError as error:
self.shutdown()
raise VectorInitializationError.from_generic(error) from None

@property
def fd(self) -> bool:
class_name = self.__class__.__name__
Expand Down