diff options
-rw-r--r-- | pyserial/examples/scanwin32.py | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/pyserial/examples/scanwin32.py b/pyserial/examples/scanwin32.py index 13cad47..090d7d6 100644 --- a/pyserial/examples/scanwin32.py +++ b/pyserial/examples/scanwin32.py @@ -181,18 +181,20 @@ def comports(available_only=True): #~ raise ctypes.WinError() # not getting friendly name for com0com devices, try something else szFriendlyName = ctypes.create_string_buffer(1024) - SetupDiGetDeviceRegistryProperty( + if SetupDiGetDeviceRegistryProperty( g_hdi, ctypes.byref(devinfo), SPDRP_LOCATION_INFORMATION, None, ctypes.byref(szFriendlyName), ctypes.sizeof(szFriendlyName) - 1, None - ) - try: - port_name = re.search(r"\((.*)\)", szFriendlyName.value).group(1) - except AttributeError, msg: - port_name = szFriendlyName.value + ): + port_name = "\\\\.\\" + szFriendlyName.value + else: + try: + port_name = re.search(r"\((.*)\)", szFriendlyName.value).group(1) + except AttributeError, msg: + port_name = szFriendlyName.value yield port_name, szFriendlyName.value, szHardwareID.value SetupDiDestroyDeviceInfoList(g_hdi) |