src/eric7/MicroPython/MicroPythonDeviceInterface.py

branch
mpy_network
changeset 9989
286c2a21f36f
parent 9826
9340ce7fb12f
child 9990
54c614d91eff
diff -r 1ba9d07ba9da -r 286c2a21f36f src/eric7/MicroPython/MicroPythonDeviceInterface.py
--- a/src/eric7/MicroPython/MicroPythonDeviceInterface.py	Mon Apr 24 17:51:11 2023 +0200
+++ b/src/eric7/MicroPython/MicroPythonDeviceInterface.py	Thu Apr 27 17:59:09 2023 +0200
@@ -427,39 +427,68 @@
         self.__blockReadyRead = False
         return out, err
 
-    def executeAsync(self, commandsList):
+    def executeAsync(self, commandsList, submitMode):
         """
         Public method to execute a series of commands over a period of time
         without returning any result (asynchronous execution).
 
         @param commandsList list of commands to be execute on the device
+        @type list of str
+        @param submitMode mode to be used to submit the commands
+        @type str (one of 'raw' or 'paste')
+        @exception ValueError raised to indicate an unknown submit mode
+        """
+        if submitMode not in ("raw", "paste"):
+            raise ValueError("Illegal submit mode given ({0})".format(submitMode))
+
+        if submitMode == "raw":
+            startSequence = [  # sequence of commands to enter raw mode
+                b"\x02",  # Ctrl-B: exit raw repl (just in case)
+                b"\r\x03\x03\x03",  # Ctrl-C three times: interrupt any running program
+                b"\r\x01",  # Ctrl-A: enter raw REPL
+                b'print("\\n")\r',
+            ]
+            endSequence = [
+                b"\r",
+                b"\x04",
+            ]
+            self.__executeAsyncRaw(
+                startSequence
+                + [c.encode("utf-8") + b"\r" for c in commandsList]
+                + endSequence
+            )
+        elif submitMode == "paste":
+            self.__executeAsyncPaste(commandsList)
+
+    def __executeAsyncRaw(self, commandsList):
+        """
+        Private method to execute a series of commands over a period of time
+        without returning any result (asynchronous execution).
+
+        @param commandsList list of commands to be execute on the device
         @type list of bytes
         """
         if commandsList:
             command = commandsList.pop(0)
             self.__serial.write(command)
-            QTimer.singleShot(2, lambda: self.executeAsync(commandsList))
+            QTimer.singleShot(2, lambda: self.__executeAsyncRaw(commandsList))
         else:
+            self.__rawOff()
             self.executeAsyncFinished.emit()
 
-    def executeAsyncPaste(self, commandsList):
+    def __executeAsyncPaste(self, commandsList):
         """
-        Public method to execute a series of commands over a period of time
+        Private method to execute a series of commands over a period of time
         without returning any result (asynchronous execution).
 
         @param commandsList list of commands to be execute on the device
-        @type list of bytes
+        @type list of str
         """
-        if commandsList:
-            self.__blockReadyRead = True
-            command = commandsList.pop(0)
-            if command == "@PasteOn@":
-                self.__pasteOn()
-            else:
-                self.__serial.write(command)
-                self.__serial.readUntil(command)
-            QTimer.singleShot(2, lambda: self.executeAsyncPaste(commandsList))
-        else:
-            self.__blockReadyRead = False
-            self.__pasteOff()
-            self.executeAsyncFinished.emit()
+        self.__blockReadyRead = True
+        self.__pasteOn()
+        command = b"\n".join(c.encode("utf-8)") for c in commandsList)
+        self.__serial.write(command)
+        self.__serial.readUntil(command)
+        self.__blockReadyRead = False
+        self.__pasteOff()
+        self.executeAsyncFinished.emit

eric ide

mercurial