14
14
import logging
15
15
import sys
16
16
import warnings
17
- from typing import Callable , Optional , Sequence , Tuple , Union
17
+ from typing import Callable , Optional , Sequence , Tuple , Union , List
18
18
19
19
from can import (
20
20
BusABC ,
29
29
from can .ctypesutil import HRESULT as ctypes_HRESULT
30
30
from can .exceptions import CanInitializationError , CanInterfaceNotImplementedError
31
31
from can .util import deprecated_args_alias
32
+ from can .typechecking import AutoDetectedConfig
32
33
33
34
from . import constants , structures
34
35
from .exceptions import *
@@ -945,7 +946,7 @@ def get_ixxat_hwids():
945
946
return hwids
946
947
947
948
948
- def _detect_available_configs ():
949
+ def _detect_available_configs () -> List [ AutoDetectedConfig ] :
949
950
950
951
config_list = [] # list in wich to store the resulting bus kwargs
951
952
@@ -957,33 +958,36 @@ def _detect_available_configs():
957
958
channel_handle = HANDLE ()
958
959
device_handle2 = HANDLE ()
959
960
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
988
992
989
993
return config_list
0 commit comments