eric6/MicroPython/MicroPythonCommandsInterface.py

changeset 8061
979562f350bf
parent 8058
9769eb548f0d
child 8115
cef34b4ee310
diff -r 78aea20be1ec -r 979562f350bf eric6/MicroPython/MicroPythonCommandsInterface.py
--- a/eric6/MicroPython/MicroPythonCommandsInterface.py	Wed Feb 03 16:42:04 2021 +0100
+++ b/eric6/MicroPython/MicroPythonCommandsInterface.py	Wed Feb 03 19:14:35 2021 +0100
@@ -143,11 +143,17 @@
         rawReplMessage = b"raw REPL; CTRL-B to exit\r\n>"
         
         self.__serial.write(b"\x02")        # end raw mode if required
-        self.__serial.waitForBytesWritten()
+        written = self.__serial.waitForBytesWritten(500)
+        # time out after 500ms if device is not responding
+        if not written:
+            return False
         for _i in range(3):
             # CTRL-C three times to break out of loops
             self.__serial.write(b"\r\x03")
-            self.__serial.waitForBytesWritten()
+            written = self.__serial.waitForBytesWritten(500)
+            # time out after 500ms if device is not responding
+            if not written:
+                return False
             QThread.msleep(10)
         self.__serial.readAll()             # read all data and discard it
         self.__serial.write(b"\r\x01")      # send CTRL-A to enter raw mode
@@ -806,21 +812,30 @@
         @exception OSError raised to indicate an issue with the device
         """
         commands = [
-            "import time as __time_",
             "\n".join([
                 "try:",
-                "    print(__time_.strftime('%Y-%m-%d %H:%M:%S',"
+                "    import rtc as __rtc_",
+                "    print('{0:04d}-{1:02d}-{2:02d} {3:02d}:{4:02d}:{5:02d}'"
+                ".format(*__rtc_.RTC().datetime[:6]))",
+                "    del __rtc_",
+                "except:",
+                "    import time as __time_",
+                "    try:",
+                "        print(__time_.strftime('%Y-%m-%d %H:%M:%S',"
                 # __IGNORE_WARNING_M601__
                 " __time_.localtime()))",
-                "except AttributeError:",
-                "    tm = __time_.localtime()",
-                "    print('{0:04d}-{1:02d}-{2:02d} {3:02d}:{4:02d}:{5:02d}'"
+                "    except AttributeError:",
+                "        tm = __time_.localtime()",
+                "        print('{0:04d}-{1:02d}-{2:02d}"
+                " {3:02d}:{4:02d}:{5:02d}'"
                 ".format(tm[0], tm[1], tm[2], tm[3], tm[4], tm[5]))",
-                "    del tm",
+                "        del tm",
+                "    del __time_"
             ]),
-            "del __time_"
         ]
         out, err = self.execute(commands)
         if err:
+            if b"NotImplementedError" in err:
+                return "<unsupported> <unsupported>"
             raise OSError(self.__shortError(err))
         return out.decode("utf-8").strip()

eric ide

mercurial