src/eric7/MicroPython/Devices/DeviceBase.py

branch
mpy_network
changeset 9799
a79430a8811d
parent 9798
4402d76c5fa9
child 9802
22aeee2bf35f
--- a/src/eric7/MicroPython/Devices/DeviceBase.py	Fri Feb 24 18:36:43 2023 +0100
+++ b/src/eric7/MicroPython/Devices/DeviceBase.py	Sat Feb 25 19:18:07 2023 +0100
@@ -95,6 +95,8 @@
         self.microPython = microPythonWidget
         self._deviceData = {}  # dictionary with essential device data
 
+        self.submitMode = "raw"  # default is 'raw' mode to submit commands
+
     def setConnected(self, connected):
         """
         Public method to set the connection state.
@@ -319,6 +321,7 @@
             # user cancelled
             return ""
 
+    # TODO: add sending in 'paste' mode
     def sendCommands(self, commandsList):
         """
         Public method to send a list of commands to the device.
@@ -326,21 +329,25 @@
         @param commandsList list of commands to be sent to the device
         @type list of str
         """
-        rawOn = [  # 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
-        ]
-        newLine = [
-            b'print("\\n")\r',
-        ]
-        commands = [c.encode("utf-8)") + b"\r" for c in commandsList]
-        commands.append(b"\r")
-        commands.append(b"\x04")
-        rawOff = [b"\x02", b"\x02"]
-        commandSequence = rawOn + newLine + commands + rawOff
-        self._interface.executeAsync(commandSequence)
+        if self.submitMode == "raw":
+            rawOn = [  # 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
+            ]
+            newLine = [
+                b'print("\\n")\r',
+            ]
+            commands = [c.encode("utf-8)") + b"\r" for c in commandsList]
+            commands.append(b"\r")
+            commands.append(b"\x04")
+            rawOff = [b"\x02", b"\x02"]
+            commandSequence = rawOn + newLine + commands + rawOff
+            self._interface.executeAsync(commandSequence)
+        elif self.submitMode == "paste":
+            commands = b"\n".join([c.encode("utf-8)") for c in commandsList])
+            commandSequence = ["@PasteOn@", commands]
+            self._interface.executeAsyncPaste(commandSequence)
 
     @pyqtSlot()
     def handleDataFlood(self):
@@ -473,7 +480,7 @@
 """.format(
             dirname
         )
-        out, err = self._interface.execute(command)
+        out, err = self._interface.execute(command, mode=self.submitMode)
         if err:
             raise OSError(self._shortError(err))
         return ast.literal_eval(out.decode("utf-8"))
@@ -525,7 +532,7 @@
 """.format(
             dirname, showHidden
         )
-        out, err = self._interface.execute(command)
+        out, err = self._interface.execute(command, mode=self.submitMode)
         if err:
             raise OSError(self._shortError(err))
         fileslist = ast.literal_eval(out.decode("utf-8"))
@@ -553,7 +560,7 @@
 """.format(
                 dirname
             )
-            out, err = self._interface.execute(command)
+            out, err = self._interface.execute(command, mode=self.submitMode)
             if err:
                 raise OSError(self._shortError(err))
 
@@ -570,7 +577,7 @@
 print(__os_.getcwd())
 del __os_
 """
-        out, err = self._interface.execute(command)
+        out, err = self._interface.execute(command, mode=self.submitMode)
         if err:
             raise OSError(self._shortError(err))
         return out.decode("utf-8").strip()
@@ -595,7 +602,7 @@
 """.format(
                 filename
             )
-            out, err = self._interface.execute(command)
+            out, err = self._interface.execute(command, mode=self.submitMode)
             if err:
                 raise OSError(self._shortError(err))
 
@@ -642,7 +649,7 @@
 """.format(
                 name, recursive, force
             )
-            out, err = self._interface.execute(command)
+            out, err = self._interface.execute(command, mode=self.submitMode)
             if err:
                 raise OSError(self._shortError(err))
             return ast.literal_eval(out.decode("utf-8"))
@@ -665,7 +672,7 @@
 """.format(
                 dirname
             )
-            out, err = self._interface.execute(command)
+            out, err = self._interface.execute(command, mode=self.submitMode)
             if err:
                 raise OSError(self._shortError(err))
 
@@ -692,7 +699,7 @@
 """.format(
                 dirname
             )
-            out, err = self._interface.execute(command)
+            out, err = self._interface.execute(command, mode=self.submitMode)
             if err:
                 raise OSError(self._shortError(err))
 
@@ -754,7 +761,7 @@
         )
         command = "\n".join(commands)
 
-        out, err = self._interface.execute(command)
+        out, err = self._interface.execute(command, mode=self.submitMode)
         if err:
             raise OSError(self._shortError(err))
         return True
@@ -823,7 +830,7 @@
 """.format(
             deviceFileName
         )
-        out, err = self._interface.execute(command)
+        out, err = self._interface.execute(command, mode=self.submitMode)
         if err:
             raise OSError(self._shortError(err))
 
@@ -862,7 +869,7 @@
 print(fsinfo())
 del __os_, fsinfo
 """
-        out, err = self._interface.execute(command)
+        out, err = self._interface.execute(command, mode=self.submitMode)
         if err:
             raise OSError(self._shortError(err))
         infolist = ast.literal_eval(out.decode("utf-8"))
@@ -935,7 +942,7 @@
 print(res)
 del res, uname, __os_, __sys_
 """
-        out, err = self._interface.execute(command)
+        out, err = self._interface.execute(command, mode=self.submitMode)
         if err:
             raise OSError(self._shortError(err))
         return ast.literal_eval(out.decode("utf-8"))
@@ -1042,9 +1049,9 @@
     res['ulab'] = None
 
 print(res)
-del res, __os_, __sys_
+del res, __os_, __sys_, uname
 """
-        out, err = self._interface.execute(command)
+        out, err = self._interface.execute(command, mode=self.submitMode)
         if err:
             raise OSError(self._shortError(err))
         return ast.literal_eval(out.decode("utf-8"))
@@ -1058,7 +1065,7 @@
         @exception OSError raised to indicate an issue with the device
         """
         commands = ["help('modules')"]
-        out, err = self._interface.execute(commands)
+        out, err = self._interface.execute(commands, mode=self.submitMode)
         if err:
             raise OSError(self._shortError(err))
 
@@ -1100,7 +1107,7 @@
         del tm
     del __time_
 """
-        out, err = self._interface.execute(command)
+        out, err = self._interface.execute(command, mode=self.submitMode)
         if err:
             if b"NotImplementedError" in err:
                 return "<unsupported> <unsupported>"
@@ -1172,7 +1179,7 @@
                     now.tm_isdst,
                 ),
             )
-            out, err = self._interface.execute(command)
+            out, err = self._interface.execute(command, mode=self.submitMode)
             if err:
                 raise OSError(self._shortError(err))
 

eric ide

mercurial