Skip to content

Commit a8f93bb

Browse files
committed
Add _detect_available_configs to ixxat bus
1 parent 2582fe9 commit a8f93bb

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

can/interfaces/ixxat/canlib.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,7 @@ def _send_periodic_internal(
156156
duration: Optional[float] = None,
157157
modifier_callback: Optional[Callable[[Message], None]] = None,
158158
) -> CyclicSendTaskABC:
159-
return self.bus._send_periodic_internal(
160-
msgs, period, duration, modifier_callback
161-
)
159+
return self.bus._send_periodic_internal(msgs, period, duration, modifier_callback)
162160

163161
def shutdown(self) -> None:
164162
super().shutdown()
@@ -170,3 +168,7 @@ def state(self) -> BusState:
170168
Return the current state of the hardware
171169
"""
172170
return self.bus.state
171+
172+
@staticmethod
173+
def _detect_available_configs():
174+
return vcinpl._detect_available_configs()

can/interfaces/ixxat/canlib_vcinpl.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,3 +942,47 @@ def get_ixxat_hwids():
942942
_canlib.vciEnumDeviceClose(device_handle)
943943

944944
return hwids
945+
946+
947+
def _detect_available_configs():
948+
949+
config_list = [] # list in wich to store the resulting bus kwargs
950+
951+
# used to detect HWID
952+
device_handle = HANDLE()
953+
device_info = structures.VCIDEVICEINFO()
954+
955+
# used to attempt to open channels
956+
channel_handle = HANDLE()
957+
device_handle2 = HANDLE()
958+
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)
987+
988+
return config_list

0 commit comments

Comments
 (0)