Skip to content

Commit 8810aa9

Browse files
committed
fix auto selece com port bug
1 parent 31764cf commit 8810aa9

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

kflash.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -803,17 +803,21 @@ def flash_firmware(self, firmware_bin: bytes, aes_key: bytes = None, address_off
803803
print(INFO_MSG,'ANSI colors not used',BASH_TIPS['DEFAULT'])
804804

805805
if args.port == "DEFAULT":
806-
try:
807-
if args.Board == "goE":
808-
list_port_info = list(serial.tools.list_ports.grep("0403")) #Take the second one
809-
print(INFO_MSG,"COM Port Auto Detected, Selected ",list_port_info[1].device,BASH_TIPS['DEFAULT'])
810-
_port = list_port_info[1].device
811-
else:
812-
list_port_info = list(serial.tools.list_ports.grep(VID_LIST_FOR_AUTO_LOOKUP)) #Take the first one within the list
813-
_port = list_port_info[0].device
814-
except StopIteration:
815-
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'])
816-
sys.exit(1)
806+
if args.Board == "goE":
807+
list_port_info = list(serial.tools.list_ports.grep("0403")) #Take the second one
808+
if(len(list_port_info)==0):
809+
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'])
810+
sys.exit(1)
811+
list_port_info.sort()
812+
print(INFO_MSG,"COM Port Auto Detected, Selected ",list_port_info[1].device,BASH_TIPS['DEFAULT'])
813+
_port = list_port_info[1].device
814+
else:
815+
try:
816+
list_port_info = next(serial.tools.list_ports.grep(VID_LIST_FOR_AUTO_LOOKUP)) #Take the first one within the list
817+
_port = list_port_info.device
818+
except StopIteration:
819+
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'])
820+
sys.exit(1)
817821
else:
818822
_port = args.port
819823
print(INFO_MSG,"COM Port Selected Manually: ",_port,BASH_TIPS['DEFAULT'])

0 commit comments

Comments
 (0)