Improved the CircuitPython device class and fixed som issues in the MPy REPL and main widget. eric7

Tue, 26 Nov 2024 19:46:36 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 26 Nov 2024 19:46:36 +0100
branch
eric7
changeset 11055
e68bcb2b5ec1
parent 11054
38ffc8fbc782
child 11056
cef972a17097

Improved the CircuitPython device class and fixed som issues in the MPy REPL and main widget.

src/eric7/MicroPython/Devices/CircuitPythonDevices.py file | annotate | diff | comparison | revisions
src/eric7/MicroPython/MicroPythonReplWidget.py file | annotate | diff | comparison | revisions
src/eric7/MicroPython/MicroPythonWidget.py file | annotate | diff | comparison | revisions
diff -r 38ffc8fbc782 -r e68bcb2b5ec1 src/eric7/MicroPython/Devices/CircuitPythonDevices.py
--- a/src/eric7/MicroPython/Devices/CircuitPythonDevices.py	Tue Nov 26 17:07:48 2024 +0100
+++ b/src/eric7/MicroPython/Devices/CircuitPythonDevices.py	Tue Nov 26 19:46:36 2024 +0100
@@ -756,7 +756,7 @@
         import wifi
         if hasattr(wifi, 'radio'):
             return True, 'circuitpython'
-    except ImportError:
+    except (ImportError, MemoryError):
         pass
 
     return False, ''
@@ -764,10 +764,13 @@
 print(has_wifi())
 del has_wifi
 """
-        out, err = self.executeCommands(command, mode=self._submitMode)
-        if err:
-            raise OSError(self._shortError(err))
-        return ast.literal_eval(out.decode("utf-8"))
+        try:
+            return self._deviceData["wifi"], self._deviceData["wifi_type"]
+        except KeyError:
+            out, err = self.executeCommands(command, mode=self._submitMode)
+            if err:
+                raise OSError(self._shortError(err))
+            return ast.literal_eval(out.decode("utf-8"))
 
     def getWifiData(self):
         """
@@ -1352,12 +1355,16 @@
 print(has_eth())
 del has_eth
 """
+        try:
+            return self._deviceData["ethernet"], self._deviceData["ethernet_type"]
+        except KeyError:
+            out, err = self.executeCommands(
+                command, mode=self._submitMode, timeout=10000
+            )
+            if err:
+                raise OSError(self._shortError(err))
 
-        out, err = self.executeCommands(command, mode=self._submitMode, timeout=10000)
-        if err:
-            raise OSError(self._shortError(err))
-
-        return ast.literal_eval(out.decode("utf-8"))
+            return ast.literal_eval(out.decode("utf-8"))
 
     def getEthernetStatus(self):
         """
@@ -1707,10 +1714,15 @@
 print(has_bt())
 del has_bt
 """
-        out, err = self.executeCommands(command, mode=self._submitMode, timeout=10000)
-        if err:
-            raise OSError(self._shortError(err))
-        return out.strip() == b"True"
+        try:
+            return self._deviceData["bluetooth"]
+        except KeyError:
+            out, err = self.executeCommands(
+                command, mode=self._submitMode, timeout=10000
+            )
+            if err:
+                raise OSError(self._shortError(err))
+            return out.strip() == b"True"
 
     def getBluetoothStatus(self):
         """
diff -r 38ffc8fbc782 -r e68bcb2b5ec1 src/eric7/MicroPython/MicroPythonReplWidget.py
--- a/src/eric7/MicroPython/MicroPythonReplWidget.py	Tue Nov 26 17:07:48 2024 +0100
+++ b/src/eric7/MicroPython/MicroPythonReplWidget.py	Tue Nov 26 19:46:36 2024 +0100
@@ -576,7 +576,10 @@
                     length = 2
                 else:
                     length = 1
-                txt = data[index : index + length].decode("utf8")
+                try:
+                    txt = data[index : index + length].decode("utf8")
+                except UnicodeDecodeError:
+                    txt = data[index : index + length].decode("iso8859-1")
                 index += length - 1  # one more is done at the end
                 self.insertPlainText(txt)
 
diff -r 38ffc8fbc782 -r e68bcb2b5ec1 src/eric7/MicroPython/MicroPythonWidget.py
--- a/src/eric7/MicroPython/MicroPythonWidget.py	Tue Nov 26 17:07:48 2024 +0100
+++ b/src/eric7/MicroPython/MicroPythonWidget.py	Tue Nov 26 19:46:36 2024 +0100
@@ -538,6 +538,8 @@
                 return
 
             self.replWidget.replEdit().clear()
+            if self.__interface is None:
+                return
             self.__interface.dataReceived.connect(
                 self.replWidget.replEdit().processData
             )

eric ide

mercurial