|
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, List, Optional, Sequence, Tuple, Union |
18 | 18 |
|
19 | 19 | from can import ( |
20 | 20 | BusABC, |
|
28 | 28 | from can.ctypesutil import HANDLE, PHANDLE, CLibrary |
29 | 29 | from can.ctypesutil import HRESULT as ctypes_HRESULT |
30 | 30 | from can.exceptions import CanInitializationError, CanInterfaceNotImplementedError |
| 31 | +from can.typechecking import AutoDetectedConfig |
31 | 32 | from can.util import deprecated_args_alias |
32 | 33 |
|
33 | 34 | from . import constants, structures |
@@ -943,3 +944,55 @@ def get_ixxat_hwids(): |
943 | 944 | _canlib.vciEnumDeviceClose(device_handle) |
944 | 945 |
|
945 | 946 | return hwids |
| 947 | + |
| 948 | + |
| 949 | +def _detect_available_configs() -> List[AutoDetectedConfig]: |
| 950 | + config_list = [] # list in wich to store the resulting bus kwargs |
| 951 | + |
| 952 | + # used to detect HWID |
| 953 | + device_handle = HANDLE() |
| 954 | + device_info = structures.VCIDEVICEINFO() |
| 955 | + |
| 956 | + # used to attempt to open channels |
| 957 | + channel_handle = HANDLE() |
| 958 | + device_handle2 = HANDLE() |
| 959 | + |
| 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( |
| 987 | + { |
| 988 | + "interface": "ixxat", |
| 989 | + "channel": channel, |
| 990 | + "unique_hardware_id": hwid, |
| 991 | + } |
| 992 | + ) |
| 993 | + _canlib.vciDeviceClose(device_handle2) |
| 994 | + _canlib.vciEnumDeviceClose(device_handle) |
| 995 | + except AttributeError: |
| 996 | + pass # _canlib is None in the CI tests -> return a blank list |
| 997 | + |
| 998 | + return config_list |
0 commit comments