Skip to content

Commit ddc7c35

Browse files
authored
Fix Vector channel detection (hardbyte#1634)
1 parent 78d25ff commit ddc7c35

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

can/interfaces/vector/canlib.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,11 @@ def _read_bus_params(self, channel: int) -> "VectorBusParams":
400400
vcc_list = get_channel_configs()
401401
for vcc in vcc_list:
402402
if vcc.channel_mask == channel_mask:
403-
return vcc.bus_params
403+
bus_params = vcc.bus_params
404+
if bus_params is None:
405+
# for CAN channels, this should never be `None`
406+
raise ValueError("Invalid bus parameters.")
407+
return bus_params
404408

405409
raise CanInitializationError(
406410
f"Channel configuration for channel {channel} not found."
@@ -1090,7 +1094,7 @@ class VectorChannelConfig(NamedTuple):
10901094
channel_bus_capabilities: xldefine.XL_BusCapabilities
10911095
is_on_bus: bool
10921096
connected_bus_type: xldefine.XL_BusTypes
1093-
bus_params: VectorBusParams
1097+
bus_params: Optional[VectorBusParams]
10941098
serial_number: int
10951099
article_number: int
10961100
transceiver_name: str
@@ -1110,9 +1114,14 @@ def _get_xl_driver_config() -> xlclass.XLdriverConfig:
11101114
return driver_config
11111115

11121116

1113-
def _read_bus_params_from_c_struct(bus_params: xlclass.XLbusParams) -> VectorBusParams:
1117+
def _read_bus_params_from_c_struct(
1118+
bus_params: xlclass.XLbusParams,
1119+
) -> Optional[VectorBusParams]:
1120+
bus_type = xldefine.XL_BusTypes(bus_params.busType)
1121+
if bus_type is not xldefine.XL_BusTypes.XL_BUS_TYPE_CAN:
1122+
return None
11141123
return VectorBusParams(
1115-
bus_type=xldefine.XL_BusTypes(bus_params.busType),
1124+
bus_type=bus_type,
11161125
can=VectorCanParams(
11171126
bitrate=bus_params.data.can.bitRate,
11181127
sjw=bus_params.data.can.sjw,

0 commit comments

Comments
 (0)