Skip to content
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

Fix Vector channel detection #1634

Merged
merged 1 commit into from
Jul 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 13 additions & 4 deletions can/interfaces/vector/canlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,11 @@ def _read_bus_params(self, channel: int) -> "VectorBusParams":
vcc_list = get_channel_configs()
for vcc in vcc_list:
if vcc.channel_mask == channel_mask:
return vcc.bus_params
bus_params = vcc.bus_params
if bus_params is None:
# for CAN channels, this should never be `None`
raise ValueError("Invalid bus parameters.")
return bus_params

raise CanInitializationError(
f"Channel configuration for channel {channel} not found."
Expand Down Expand Up @@ -1090,7 +1094,7 @@ class VectorChannelConfig(NamedTuple):
channel_bus_capabilities: xldefine.XL_BusCapabilities
is_on_bus: bool
connected_bus_type: xldefine.XL_BusTypes
bus_params: VectorBusParams
bus_params: Optional[VectorBusParams]
serial_number: int
article_number: int
transceiver_name: str
Expand All @@ -1110,9 +1114,14 @@ def _get_xl_driver_config() -> xlclass.XLdriverConfig:
return driver_config


def _read_bus_params_from_c_struct(bus_params: xlclass.XLbusParams) -> VectorBusParams:
def _read_bus_params_from_c_struct(
bus_params: xlclass.XLbusParams,
) -> Optional[VectorBusParams]:
bus_type = xldefine.XL_BusTypes(bus_params.busType)
if bus_type is not xldefine.XL_BusTypes.XL_BUS_TYPE_CAN:
return None
return VectorBusParams(
bus_type=xldefine.XL_BusTypes(bus_params.busType),
bus_type=bus_type,
can=VectorCanParams(
bitrate=bus_params.data.can.bitRate,
sjw=bus_params.data.can.sjw,
Expand Down