eric6/MicroPython/MicroPythonCommandsInterface.py

branch
micropython
changeset 7108
4f6133a01c6a
parent 7102
5e77aa4671e6
child 7112
701cdc76f887
diff -r aea236dc8002 -r 4f6133a01c6a eric6/MicroPython/MicroPythonCommandsInterface.py
--- a/eric6/MicroPython/MicroPythonCommandsInterface.py	Tue Jul 30 19:44:27 2019 +0200
+++ b/eric6/MicroPython/MicroPythonCommandsInterface.py	Wed Jul 31 20:41:39 2019 +0200
@@ -13,7 +13,7 @@
 import time
 import os
 
-from PyQt5.QtCore import pyqtSlot, pyqtSignal, QObject, QThread, QTimer
+from PyQt5.QtCore import pyqtSlot, pyqtSignal, QObject, QThread, QTimer, QCoreApplication, QEventLoop
 
 from .MicroPythonSerialPort import MicroPythonSerialPort
 
@@ -137,7 +137,7 @@
         if not self.__serial:
             return False
         
-        rawReplMessage = b"raw REPL; CTRL-B to exit\r\n"
+        rawReplMessage = b"raw REPL; CTRL-B to exit\r\n>"
         softRebootMessage = b"soft reboot\r\n"
         
         self.__serial.write(b"\x02")        # end raw mode if required
@@ -160,13 +160,12 @@
         # some MicroPython devices seem to need to be convinced in some
         # special way
         data = self.__serial.readUntil(rawReplMessage)
-        if self.__serial.hasTimedOut():
-            return False
         if not data.endswith(rawReplMessage):
             self.__serial.write(b"\r\x01")  # send CTRL-A again
             self.__serial.readUntil(rawReplMessage)
             if self.__serial.hasTimedOut():
                 return False
+        QCoreApplication.processEvents(QEventLoop.ExcludeUserInputEvents)
         self.__serial.readAll()             # read all data and discard it
         return True
     
@@ -717,7 +716,7 @@
         if err:
             raise IOError(self.__shortError(err))
     
-    def showTime(self):
+    def getTime(self):
         """
         Public method to get the current time of the device.
         
@@ -727,8 +726,17 @@
         """
         commands = [
             "import time",
-            "print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()))",
-            # __IGNORE_WARNING_M601__
+            "\n".join([
+                "try:",
+                "    print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()"
+                "))",
+                # __IGNORE_WARNING_M601__
+                "except AttributeError:",
+                "    tm = time.localtime()",
+                "    print('{0:04d}-{1:02d}-{2:02d} {3:02d}:{4:02d}:{5:02d}'"
+                ".format(tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour,"
+                " tm.tm_min, tm.tm_sec))",
+            ]),
         ]
         out, err = self.execute(commands)
         if err:

eric ide

mercurial