diff options
author | Chris Liechti <cliechti@gmx.net> | 2016-08-06 01:54:49 +0200 |
---|---|---|
committer | Chris Liechti <cliechti@gmx.net> | 2016-08-06 01:54:49 +0200 |
commit | 1532e47a718acacc8cd25b5a155aca38f186f976 (patch) | |
tree | 38b27c780a6140de332a2b42ffb29c18a7d5d41d /serial/tools/list_ports_windows.py | |
parent | 2c84964936cdbe16c623ff874b7a528cc9d7a50d (diff) | |
download | pyserial-git-1532e47a718acacc8cd25b5a155aca38f186f976.tar.gz |
list_ports_windows: support devices with only VID. fixes #145
- PID field is now optional (regexp)
- if vid or pid is None, use a 0 for display
Diffstat (limited to 'serial/tools/list_ports_windows.py')
-rw-r--r-- | serial/tools/list_ports_windows.py | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/serial/tools/list_ports_windows.py b/serial/tools/list_ports_windows.py index 810417e..a070559 100644 --- a/serial/tools/list_ports_windows.py +++ b/serial/tools/list_ports_windows.py @@ -209,12 +209,13 @@ def iterate_comports(): # in case of USB, make a more readable string, similar to that form # that we also generate on other platforms if szHardwareID_str.startswith('USB'): - m = re.search(r'VID_([0-9a-f]{4})&PID_([0-9a-f]{4})(\\(\w+))?', szHardwareID_str, re.I) + m = re.search(r'VID_([0-9a-f]{4})(&PID_([0-9a-f]{4}))?(\\(\w+))?', szHardwareID_str, re.I) if m: info.vid = int(m.group(1), 16) - info.pid = int(m.group(2), 16) - if m.group(4): - info.serial_number = m.group(4) + if m.group(3): + info.pid = int(m.group(3), 16) + if m.group(5): + info.serial_number = m.group(5) # calculate a location string loc_path_str = ctypes.create_unicode_buffer(250) if SetupDiGetDeviceRegistryProperty( |