Skip to content

Commit 8c7ab68

Browse files
committed
Add typing and cover CI test failure
1 parent a8f93bb commit 8c7ab68

File tree

2 files changed

+37
-32
lines changed

2 files changed

+37
-32
lines changed

can/interfaces/ixxat/canlib.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Callable, Optional, Sequence, Union
1+
from typing import Callable, Optional, Sequence, Union, List
22

33
import can.interfaces.ixxat.canlib_vcinpl as vcinpl
44
import can.interfaces.ixxat.canlib_vcinpl2 as vcinpl2
@@ -8,6 +8,7 @@
88
CyclicSendTaskABC,
99
Message,
1010
)
11+
from can.typechecking import AutoDetectedConfig
1112

1213

1314
class IXXATBus(BusABC):
@@ -170,5 +171,5 @@ def state(self) -> BusState:
170171
return self.bus.state
171172

172173
@staticmethod
173-
def _detect_available_configs():
174+
def _detect_available_configs() -> List[AutoDetectedConfig]:
174175
return vcinpl._detect_available_configs()

can/interfaces/ixxat/canlib_vcinpl.py

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import logging
1515
import sys
1616
import warnings
17-
from typing import Callable, Optional, Sequence, Tuple, Union
17+
from typing import Callable, Optional, Sequence, Tuple, Union, List
1818

1919
from can import (
2020
BusABC,
@@ -29,6 +29,7 @@
2929
from can.ctypesutil import HRESULT as ctypes_HRESULT
3030
from can.exceptions import CanInitializationError, CanInterfaceNotImplementedError
3131
from can.util import deprecated_args_alias
32+
from can.typechecking import AutoDetectedConfig
3233

3334
from . import constants, structures
3435
from .exceptions import *
@@ -944,7 +945,7 @@ def get_ixxat_hwids():
944945
return hwids
945946

946947

947-
def _detect_available_configs():
948+
def _detect_available_configs() -> List[AutoDetectedConfig]:
948949

949950
config_list = [] # list in wich to store the resulting bus kwargs
950951

@@ -956,33 +957,36 @@ def _detect_available_configs():
956957
channel_handle = HANDLE()
957958
device_handle2 = HANDLE()
958959

959-
_canlib.vciEnumDeviceOpen(ctypes.byref(device_handle))
960-
while True:
961-
try:
962-
_canlib.vciEnumDeviceNext(device_handle, ctypes.byref(device_info))
963-
except StopIteration:
964-
break
965-
else:
966-
hwid = device_info.UniqueHardwareId.AsChar.decode("ascii")
967-
_canlib.vciDeviceOpen(
968-
ctypes.byref(device_info.VciObjectId),
969-
ctypes.byref(device_handle2),
970-
)
971-
for channel in range(4):
972-
try:
973-
_canlib.canChannelOpen(
974-
device_handle2,
975-
channel,
976-
constants.FALSE,
977-
ctypes.byref(channel_handle),
978-
)
979-
except Exception:
980-
# Array outside of bounds error == accessing a channel not in the hardware
981-
break
982-
else:
983-
_canlib.canChannelClose(channel_handle)
984-
config_list.append({"interface": "ixxat", "channel": channel, "unique_hardware_id": hwid})
985-
_canlib.vciDeviceClose(device_handle2)
986-
_canlib.vciEnumDeviceClose(device_handle)
960+
try:
961+
_canlib.vciEnumDeviceOpen(ctypes.byref(device_handle))
962+
while True:
963+
try:
964+
_canlib.vciEnumDeviceNext(device_handle, ctypes.byref(device_info))
965+
except StopIteration:
966+
break
967+
else:
968+
hwid = device_info.UniqueHardwareId.AsChar.decode("ascii")
969+
_canlib.vciDeviceOpen(
970+
ctypes.byref(device_info.VciObjectId),
971+
ctypes.byref(device_handle2),
972+
)
973+
for channel in range(4):
974+
try:
975+
_canlib.canChannelOpen(
976+
device_handle2,
977+
channel,
978+
constants.FALSE,
979+
ctypes.byref(channel_handle),
980+
)
981+
except Exception:
982+
# Array outside of bounds error == accessing a channel not in the hardware
983+
break
984+
else:
985+
_canlib.canChannelClose(channel_handle)
986+
config_list.append({"interface": "ixxat", "channel": channel, "unique_hardware_id": hwid})
987+
_canlib.vciDeviceClose(device_handle2)
988+
_canlib.vciEnumDeviceClose(device_handle)
989+
except AttributeError:
990+
pass # _canlib is None in the CI tests -> return a blank list
987991

988992
return config_list

0 commit comments

Comments
 (0)