From a24d1787de0fd44a5b68d056268bda63404c6f94 Mon Sep 17 00:00:00 2001 From: James Teh Date: Fri, 14 Oct 2016 11:29:54 +1000 Subject: [PATCH 1/2] Fixed another rare issue when scanning for serial ports on some systems which made some braille display drivers unusable. hwPortUtils.listComPorts: In some rare cases, the SPDRP_FRIENDLYNAME registry property doesn't exist/isn't valid. In these cases, just use the port name as the friendly name. Re #6007. --- source/hwPortUtils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/hwPortUtils.py b/source/hwPortUtils.py index 9e387f5a5c0..d318e8083ab 100644 --- a/source/hwPortUtils.py +++ b/source/hwPortUtils.py @@ -231,7 +231,9 @@ def __str__(self): ): # Ignore ERROR_INSUFFICIENT_BUFFER if ctypes.GetLastError() != ERROR_INSUFFICIENT_BUFFER: - raise ctypes.WinError() + # #6007: SPDRP_FRIENDLYNAME sometimes doesn't exist/isn't valid. + log.debugWarning("Couldn't get SPDRP_FRIENDLYNAME for %s: %s" % (port, ctypes.WinError())) + entry["friendlyName"] = port else: entry["friendlyName"] = buf.value From 52057dfff35d8210daf63f0ac437037e175e4ac4 Mon Sep 17 00:00:00 2001 From: James Teh Date: Tue, 18 Oct 2016 14:17:20 +1000 Subject: [PATCH 2/2] hwPortUtils.listComPorts: Handle PortName being empty just in case. For FriendlyName, log a warning and fall back to PortName for ERROR_INSUFFICIENT_BUFFER too. --- source/hwPortUtils.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/source/hwPortUtils.py b/source/hwPortUtils.py index d318e8083ab..a595cf7dc95 100644 --- a/source/hwPortUtils.py +++ b/source/hwPortUtils.py @@ -196,6 +196,9 @@ def __str__(self): # #6015: In some rare cases, this value doesn't exist. log.debugWarning("No PortName value for hardware ID %s" % hwID) continue + if not port: + log.debugWarning("Empty PortName value for hardware ID %s" % hwID) + continue if hwID.startswith("BTHENUM\\"): # This is a Microsoft bluetooth port. try: @@ -229,11 +232,9 @@ def __str__(self): ctypes.byref(buf), ctypes.sizeof(buf) - 1, None ): - # Ignore ERROR_INSUFFICIENT_BUFFER - if ctypes.GetLastError() != ERROR_INSUFFICIENT_BUFFER: - # #6007: SPDRP_FRIENDLYNAME sometimes doesn't exist/isn't valid. - log.debugWarning("Couldn't get SPDRP_FRIENDLYNAME for %s: %s" % (port, ctypes.WinError())) - entry["friendlyName"] = port + # #6007: SPDRP_FRIENDLYNAME sometimes doesn't exist/isn't valid. + log.debugWarning("Couldn't get SPDRP_FRIENDLYNAME for %s: %s" % (port, ctypes.WinError())) + entry["friendlyName"] = port else: entry["friendlyName"] = buf.value