Skip to content

Commit 2c60427

Browse files
MattWoodheadzariiii9003
authored andcommitted
Add typing and cover CI test failure
1 parent 3dfa261 commit 2c60427

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 *
@@ -945,7 +946,7 @@ def get_ixxat_hwids():
945946
return hwids
946947

947948

948-
def _detect_available_configs():
949+
def _detect_available_configs() -> List[AutoDetectedConfig]:
949950

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

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

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

989993
return config_list

0 commit comments

Comments
 (0)