diff --git a/can/interfaces/ixxat/canlib_vcinpl.py b/can/interfaces/ixxat/canlib_vcinpl.py index 7c4becafd..307cf1d12 100644 --- a/can/interfaces/ixxat/canlib_vcinpl.py +++ b/can/interfaces/ixxat/canlib_vcinpl.py @@ -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) @@ -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", @@ -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 @@ -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),