Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions can/interfaces/ixxat/canlib_vcinpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,15 +519,20 @@ def __init__(
f"Unique HW ID {unique_hardware_id} not connected or not available."
) from None
else:
try:
hwid = self._device_info.UniqueHardwareId.AsChar.decode("ascii")
except UnicodeDecodeError:
guid = self._device_info.UniqueHardwareId.AsGuid
hwid = f"{{{guid.Data1:x}-{guid.Data2:x}-{guid.Data3:x}-{guid.Data4.hex()}}}"

if (unique_hardware_id is None) or (
self._device_info.UniqueHardwareId.AsChar
== bytes(unique_hardware_id, "ascii")
bytes(hwid, "ascii") == bytes(unique_hardware_id, "ascii")
):
break

log.debug(
"Ignoring IXXAT with hardware id '%s'.",
self._device_info.UniqueHardwareId.AsChar.decode("ascii"),
hwid,
)
_canlib.vciEnumDeviceClose(self._device_handle)

Expand All @@ -541,7 +546,7 @@ def __init__(
f"Could not open device: {exception}"
) from exception

log.info("Using unique HW ID %s", self._device_info.UniqueHardwareId.AsChar)
log.info("Using unique HW ID %s", hwid)

log.info(
"Initializing channel %d in shared mode, %d rx buffers, %d tx buffers",
Expand Down Expand Up @@ -969,7 +974,13 @@ def get_ixxat_hwids():
except StopIteration:
break
else:
hwids.append(device_info.UniqueHardwareId.AsChar.decode("ascii"))
try:
hwids.append(device_info.UniqueHardwareId.AsChar.decode("ascii"))
except UnicodeDecodeError:
guid = device_info.UniqueHardwareId.AsGuid
hwids.append(
f"{{{guid.Data1:x}-{guid.Data2:x}-{guid.Data3:x}-{guid.Data4.hex()}}}"
)
_canlib.vciEnumDeviceClose(device_handle)

return hwids
Expand All @@ -994,7 +1005,11 @@ def _detect_available_configs() -> Sequence["AutoDetectedIxxatConfig"]:
except StopIteration:
break
else:
hwid = device_info.UniqueHardwareId.AsChar.decode("ascii")
try:
hwid = device_info.UniqueHardwareId.AsChar.decode("ascii")
except UnicodeDecodeError:
guid = device_info.UniqueHardwareId.AsGuid
hwid = f"{{{guid.Data1:x}-{guid.Data2:x}-{guid.Data3:x}-{guid.Data4.hex()}}}"
_canlib.vciDeviceOpen(
ctypes.byref(device_info.VciObjectId),
ctypes.byref(device_handle2),
Expand Down
Loading