Skip to content
This repository was archived by the owner on Jan 31, 2019. It is now read-only.

Commit b8e2eec

Browse files
committed
Safely check COM port attributes (#37)
Bug fix to check if the port product exists. This caused issues when plugging in other USB COM devices, such as Arduinos who didn't have the port.product attribute. Squashed commit of the following: commit 6247987 Author: Elliot Berman <berman5@purdue.edu> Date: Wed May 31 21:20:34 2017 -0500 Fix #36
1 parent be552de commit b8e2eec

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

prosflasher/ports.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,14 @@ def list_com_ports():
1313
"""
1414
:return: Returns a list of valid serial ports that we believe are VEX Cortex Microcontrollers
1515
"""
16-
return [x for x in serial.tools.list_ports.comports() if x.vid is not None and (x.vid in USB_VID or 'vex' in x.product.lower())]
16+
def is_valid_port(p):
17+
"""
18+
Returns true if the port is has a VEX product on it by the following conditions:
19+
The Vendor ID matches the expected VEX Vendor ID (which is a default one)
20+
or VEX occurs in the product name (if it exists)
21+
"""
22+
return p.vid is not None and (p.vid in USB_VID or (isinstance(p.product, str) and 'vex' in p.product.lower()))
23+
return [p for p in serial.tools.list_ports.comports() if is_valid_port(p)]
1724

1825

1926
def create_serial(port, parity):

0 commit comments

Comments
 (0)