From c5ca0035ab7ead3199d63024afa3dd8786b1cc9c Mon Sep 17 00:00:00 2001 From: cliechti Date: Fri, 1 Aug 2014 01:38:04 +0000 Subject: [Bug pyserial:163] serial.tools.list_ports.grep() fails if it encounters None type git-svn-id: http://svn.code.sf.net/p/pyserial/code/trunk/pyserial@499 f19166aa-fa4f-0410-85c2-fa1106f25c8a --- CHANGES.txt | 5 +++++ serial/tools/list_ports_osx.py | 38 ++++++++++++++++++++------------------ 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 5741b40..d31c6d2 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -485,3 +485,8 @@ Version 2.8 2014-xx-xx Bugfixes: - [Bug pyserial:166] RFC2217 connections always fail + +Bugfixes (posix): + +- [Bug pyserial:163] serial.tools.list_ports.grep() fails if it encounters None type + diff --git a/serial/tools/list_ports_osx.py b/serial/tools/list_ports_osx.py index c9ed615..242f468 100644 --- a/serial/tools/list_ports_osx.py +++ b/serial/tools/list_ports_osx.py @@ -180,24 +180,26 @@ def comports(): info = [] # First, add the callout device file. - info.append(get_string_property(service, "IOCalloutDevice")) - - # If the serial port is implemented by a - usb_device = GetParentDeviceByType(service, "IOUSBDevice") - if usb_device != None: - info.append(get_string_property(usb_device, "USB Product Name")) - - info.append( - "USB VID:PID=%x:%x SNR=%s"%( - get_int_property(usb_device, "idVendor"), - get_int_property(usb_device, "idProduct"), - get_string_property(usb_device, "USB Serial Number")) - ) - else: - info.append('n/a') - info.append('n/a') - - ports.append(info) + device = get_string_property(service, "IOCalloutDevice") + if device: + info.append(device) + + # If the serial port is implemented by a + usb_device = GetParentDeviceByType(service, "IOUSBDevice") + if usb_device is not None: + info.append(get_string_property(usb_device, "USB Product Name") or 'n/a') + + info.append( + "USB VID:PID=%x:%x SNR=%s"%( + get_int_property(usb_device, "idVendor"), + get_int_property(usb_device, "idProduct"), + get_string_property(usb_device, "USB Serial Number")) + ) + else: + info.append('n/a') + info.append('n/a') + + ports.append(info) return ports -- cgit v1.2.1