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 *
@@ -944,7 +945,7 @@ def get_ixxat_hwids():
944
945
return hwids
945
946
946
947
947
- def _detect_available_configs ():
948
+ def _detect_available_configs () -> List [ AutoDetectedConfig ] :
948
949
949
950
config_list = [] # list in wich to store the resulting bus kwargs
950
951
@@ -956,33 +957,36 @@ def _detect_available_configs():
956
957
channel_handle = HANDLE ()
957
958
device_handle2 = HANDLE ()
958
959
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
987
991
988
992
return config_list
0 commit comments