summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a>2013-10-14 01:56:49 +0000
committercliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a>2013-10-14 01:56:49 +0000
commit53d38fcbc0980d597f5aaeff7020ec068f034c29 (patch)
tree93a9dc617b3d5253312c71b54a19d2691057189f
parent6f4bf690462c976a7e4c25ba31048bbc27a32d36 (diff)
downloadpyserial-53d38fcbc0980d597f5aaeff7020ec068f034c29.tar.gz
fix if friendly name is not available
git-svn-id: http://svn.code.sf.net/p/pyserial/code/trunk/pyserial@477 f19166aa-fa4f-0410-85c2-fa1106f25c8a
-rw-r--r--serial/tools/list_ports_windows.py16
1 files changed, 9 insertions, 7 deletions
diff --git a/serial/tools/list_ports_windows.py b/serial/tools/list_ports_windows.py
index c158dd5..6014a18 100644
--- a/serial/tools/list_ports_windows.py
+++ b/serial/tools/list_ports_windows.py
@@ -137,6 +137,7 @@ REG_SZ = 1
# workaround for compatibility between Python 2.x and 3.x
PortName = serial.to_bytes([80, 111, 114, 116, 78, 97, 109, 101]) # "PortName"
+NA = serial.to_bytes([110, 47, 97]) # "n/a"
def comports():
"""This generator scans the device registry for com ports and yields port, desc, hwid"""
@@ -175,6 +176,13 @@ def comports():
if not SetupDiGetDeviceInterfaceDetail(g_hdi, ctypes.byref(did), ctypes.byref(idd), dwNeeded, None, ctypes.byref(devinfo)):
raise ctypes.WinError()
+ # the real com port name has to read differently...
+ hkey = SetupDiOpenDevRegKey(g_hdi, ctypes.byref(devinfo), DICS_FLAG_GLOBAL, 0, DIREG_DEV, KEY_READ)
+ port_name_buffer = byte_buffer(250)
+ port_name_length = ULONG(ctypes.sizeof(port_name_buffer))
+ RegQueryValueEx(hkey, PortName, None, None, ctypes.byref(port_name_buffer), ctypes.byref(port_name_length))
+ RegCloseKey(hkey)
+
# hardware ID
szHardwareID = byte_buffer(250)
if not SetupDiGetDeviceRegistryProperty(g_hdi, ctypes.byref(devinfo), SPDRP_HARDWAREID, None, ctypes.byref(szHardwareID), ctypes.sizeof(szHardwareID) - 1, None):
@@ -189,14 +197,8 @@ def comports():
#~ if ctypes.GetLastError() != ERROR_INSUFFICIENT_BUFFER:
#~ raise IOError("failed to get details for %s (%s)" % (devinfo, szHardwareID.value))
# ignore errors and still include the port in the list, friendly name will be same as port name
- yield string(port_name_buffer), string(port_name_buffer), string(szHardwareID)
+ yield string(port_name_buffer), NA, string(szHardwareID)
else:
- # the real com port name has to read differently...
- hkey = SetupDiOpenDevRegKey(g_hdi, ctypes.byref(devinfo), DICS_FLAG_GLOBAL, 0, DIREG_DEV, KEY_READ)
- port_name_buffer = byte_buffer(250)
- port_name_length = ULONG(ctypes.sizeof(port_name_buffer))
- RegQueryValueEx(hkey, PortName, None, None, ctypes.byref(port_name_buffer), ctypes.byref(port_name_length))
- RegCloseKey(hkey)
yield string(port_name_buffer), string(szFriendlyName), string(szHardwareID)
SetupDiDestroyDeviceInfoList(g_hdi)