Skip to content

Commit 3dfa261

Browse files
MattWoodheadzariiii9003
authored andcommitted
Add _detect_available_configs to ixxat bus
1 parent e869fb7 commit 3dfa261

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
@@ -943,3 +943,47 @@ def get_ixxat_hwids():
943943
_canlib.vciEnumDeviceClose(device_handle)
944944

945945
return hwids
946+
947+
948+
def _detect_available_configs():
949+
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+
_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)
988+
989+
return config_list

0 commit comments

Comments
 (0)