Skip to content

Commit

Permalink
fix auto selece com port bug
Browse files Browse the repository at this point in the history
  • Loading branch information
xelll committed Feb 21, 2019
1 parent 31764cf commit 8810aa9
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions kflash.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,17 +803,21 @@ def flash_firmware(self, firmware_bin: bytes, aes_key: bytes = None, address_off
print(INFO_MSG,'ANSI colors not used',BASH_TIPS['DEFAULT'])

if args.port == "DEFAULT":
try:
if args.Board == "goE":
list_port_info = list(serial.tools.list_ports.grep("0403")) #Take the second one
print(INFO_MSG,"COM Port Auto Detected, Selected ",list_port_info[1].device,BASH_TIPS['DEFAULT'])
_port = list_port_info[1].device
else:
list_port_info = list(serial.tools.list_ports.grep(VID_LIST_FOR_AUTO_LOOKUP)) #Take the first one within the list
_port = list_port_info[0].device
except StopIteration:
print(ERROR_MSG,"No vaild COM Port found in Auto Detect, Check Your Connection or Specify One by"+BASH_TIPS['GREEN']+'`--port/-p`',BASH_TIPS['DEFAULT'])
sys.exit(1)
if args.Board == "goE":
list_port_info = list(serial.tools.list_ports.grep("0403")) #Take the second one
if(len(list_port_info)==0):
print(ERROR_MSG,"No vaild COM Port found in Auto Detect, Check Your Connection or Specify One by"+BASH_TIPS['GREEN']+'`--port/-p`',BASH_TIPS['DEFAULT'])
sys.exit(1)
list_port_info.sort()
print(INFO_MSG,"COM Port Auto Detected, Selected ",list_port_info[1].device,BASH_TIPS['DEFAULT'])
_port = list_port_info[1].device
else:
try:
list_port_info = next(serial.tools.list_ports.grep(VID_LIST_FOR_AUTO_LOOKUP)) #Take the first one within the list
_port = list_port_info.device
except StopIteration:
print(ERROR_MSG,"No vaild COM Port found in Auto Detect, Check Your Connection or Specify One by"+BASH_TIPS['GREEN']+'`--port/-p`',BASH_TIPS['DEFAULT'])
sys.exit(1)
else:
_port = args.port
print(INFO_MSG,"COM Port Selected Manually: ",_port,BASH_TIPS['DEFAULT'])
Expand Down

0 comments on commit 8810aa9

Please sign in to comment.