eric7/MicroPython/MicroPythonDevices.py

branch
eric7
changeset 8508
fbd629e65477
parent 8462
34bb10914b21
child 8762
49d93d0069af
--- a/eric7/MicroPython/MicroPythonDevices.py	Tue Aug 10 21:07:19 2021 +0200
+++ b/eric7/MicroPython/MicroPythonDevices.py	Mon Aug 16 19:46:20 2021 +0200
@@ -223,27 +223,36 @@
     
     availablePorts = QSerialPortInfo.availablePorts()
     for port in availablePorts:
-        supported = False
-        vid = port.vendorIdentifier()
-        pid = port.productIdentifier()
-        
-        if not port.isValid():
-            # no device detected at port
-            continue
-        
-        for board in SupportedBoards:
-            if (
-                (vid, pid) in SupportedBoards[board]["ids"] or
-                (vid, None) in SupportedBoards[board]["ids"]
-            ):
+        if port.hasVendorIdentifier() and port.hasProductIdentifier():
+            supported = False
+            vid = port.vendorIdentifier()
+            pid = port.productIdentifier()
+            
+            for board in SupportedBoards:
                 if (
-                    board in ("bbc_microbit", "calliope") and
-                    (port.description().strip() !=
-                     SupportedBoards[board]["port_description"])
+                    (vid, pid) in SupportedBoards[board]["ids"] or
+                    (vid, None) in SupportedBoards[board]["ids"]
                 ):
-                    # both boards have the same VID and PID
-                    # try to differentiate based on port description
-                    continue
+                    if (
+                        board in ("bbc_microbit", "calliope") and
+                        (port.description().strip() !=
+                         SupportedBoards[board]["port_description"])
+                    ):
+                        # both boards have the same VID and PID
+                        # try to differentiate based on port description
+                        continue
+                    foundDevices.append((
+                        board,
+                        port.description(),
+                        SupportedBoards[board]["description"],
+                        port.portName(),
+                        vid,
+                        pid,
+                    ))
+                    supported = True
+            if not supported and (vid, pid) in manualDevices:
+                # check the locally added ones next
+                board = manualDevices[(vid, pid)]["type"]
                 foundDevices.append((
                     board,
                     port.description(),
@@ -253,31 +262,19 @@
                     pid,
                 ))
                 supported = True
-        if not supported and (vid, pid) in manualDevices:
-            # check the locally added ones next
-            board = manualDevices[(vid, pid)]["type"]
-            foundDevices.append((
-                board,
-                port.description(),
-                SupportedBoards[board]["description"],
-                port.portName(),
-                vid,
-                pid,
-            ))
-            supported = True
-        if not supported:
-            if vid and pid:
-                if (vid, pid) not in IgnoredBoards:
-                    unknownDevices.append((vid, pid, port.description()))
-                    logging.debug("Unknown device: (0x%04x:0x%04x %s)",
-                                  vid, pid, port.description())
-            else:
-                # either VID or PID or both not detected
-                desc = port.description()
-                if not desc:
-                    desc = QCoreApplication.translate("MicroPythonDevice",
-                                                      "Unknown Device")
-                unknownPorts.append((vid, pid, desc, port.portName()))
+            if not supported:
+                if vid and pid:
+                    if (vid, pid) not in IgnoredBoards:
+                        unknownDevices.append((vid, pid, port.description()))
+                        logging.debug("Unknown device: (0x%04x:0x%04x %s)",
+                                      vid, pid, port.description())
+                else:
+                    # either VID or PID or both not detected
+                    desc = port.description()
+                    if not desc:
+                        desc = QCoreApplication.translate("MicroPythonDevice",
+                                                          "Unknown Device")
+                    unknownPorts.append((vid, pid, desc, port.portName()))
     
     return foundDevices, unknownDevices, unknownPorts
 

eric ide

mercurial