@@ -459,6 +459,17 @@ def on_usb_event_detected(self, message: str) -> None:
459459 port_names .append (info .description ())
460460 port_hwids .append (f"{ info .vendorIdentifier ():04X} :{ info .productIdentifier ():04X} " )
461461
462+ # Helper: exclude “debug” interfaces from auto-connect offers
463+ # ESP port name changes and contains "debug" when uploading firmware
464+ # After programming it reverts to normal port name without "debug"
465+ def is_debug_port (name : str , desc : str ) -> bool :
466+ try :
467+ name_l = (name or "" ).lower ()
468+ desc_l = (desc or "" ).lower ()
469+ return ("debug" in name_l ) or ("debug" in desc_l )
470+ except Exception :
471+ return False
472+
462473 if "USB device removed" in message :
463474 # Check if the device is still there
464475 if self .serialPort not in ports and self .serialPort != "" :
@@ -492,6 +503,13 @@ def on_usb_event_detected(self, message: str) -> None:
492503 if best_score > 0.8 :
493504 # find the port that matches the previous hwid
494505 indx = port_hwids .index (best_match )
506+ # Skip debug-class interfaces (don’t auto-reconnect to them)
507+ if is_debug_port (ports [indx ], port_names [indx ]):
508+ self .awaitingReconnection = False
509+ self .logSignal .emit (logging .INFO ,
510+ f"[{ self .instance_name [:15 ]:<15} ]: Skipping auto‑reconnect to debug interface: { ports [indx ]} ({ port_names [indx ]} )."
511+ )
512+ return
495513 self .serialPort_backup = ports [indx ]
496514 self .serialPort_previous = ports [indx ]
497515 QTimer .singleShot ( 0 , lambda : self .scanPortsRequest .emit ()) # request new port list, takes 225ms to complete
@@ -513,10 +531,16 @@ def on_usb_event_detected(self, message: str) -> None:
513531 else :
514532 # We have new device insertion, connect to it
515533 if self .serialPort == "" :
516- # new_ports = [port for port in ports if port not in self.serialPorts] # prevents device to be opened that was previously found but not opened
517- new_ports = [port for port in ports ]
518- new_portnames = [port_names [ports .index (port )] for port in new_ports if port in ports ] # Get corresponding names
534+ # Build candidate list excluding debug-class interfaces
535+ candidates = [(p , n ) for p , n in zip (ports , port_names ) if not is_debug_port (p , n )]
536+ new_ports = [p for (p , _ ) in candidates ]
537+ new_portnames = [n for (_ , n ) in candidates ]
519538
539+ if not new_ports :
540+ self .logSignal .emit (logging .INFO ,
541+ f"[{ self .instance_name [:15 ]:<15} ]: No eligible (non‑debug) USB serial device to offer for auto‑connect."
542+ )
543+ return
520544 # Figure out if useable port
521545 if new_ports :
522546 new_port = new_ports [0 ] # Consider first found new port
0 commit comments