eric6/MicroPython/MicroPythonCommandsInterface.py

changeset 8061
979562f350bf
parent 8058
9769eb548f0d
child 8115
cef34b4ee310
equal deleted inserted replaced
8060:78aea20be1ec 8061:979562f350bf
141 return False 141 return False
142 142
143 rawReplMessage = b"raw REPL; CTRL-B to exit\r\n>" 143 rawReplMessage = b"raw REPL; CTRL-B to exit\r\n>"
144 144
145 self.__serial.write(b"\x02") # end raw mode if required 145 self.__serial.write(b"\x02") # end raw mode if required
146 self.__serial.waitForBytesWritten() 146 written = self.__serial.waitForBytesWritten(500)
147 # time out after 500ms if device is not responding
148 if not written:
149 return False
147 for _i in range(3): 150 for _i in range(3):
148 # CTRL-C three times to break out of loops 151 # CTRL-C three times to break out of loops
149 self.__serial.write(b"\r\x03") 152 self.__serial.write(b"\r\x03")
150 self.__serial.waitForBytesWritten() 153 written = self.__serial.waitForBytesWritten(500)
154 # time out after 500ms if device is not responding
155 if not written:
156 return False
151 QThread.msleep(10) 157 QThread.msleep(10)
152 self.__serial.readAll() # read all data and discard it 158 self.__serial.readAll() # read all data and discard it
153 self.__serial.write(b"\r\x01") # send CTRL-A to enter raw mode 159 self.__serial.write(b"\r\x01") # send CTRL-A to enter raw mode
154 self.__serial.readUntil(rawReplMessage) 160 self.__serial.readUntil(rawReplMessage)
155 if self.__serial.hasTimedOut(): 161 if self.__serial.hasTimedOut():
804 @return time of the device 810 @return time of the device
805 @rtype str 811 @rtype str
806 @exception OSError raised to indicate an issue with the device 812 @exception OSError raised to indicate an issue with the device
807 """ 813 """
808 commands = [ 814 commands = [
809 "import time as __time_",
810 "\n".join([ 815 "\n".join([
811 "try:", 816 "try:",
812 " print(__time_.strftime('%Y-%m-%d %H:%M:%S'," 817 " import rtc as __rtc_",
818 " print('{0:04d}-{1:02d}-{2:02d} {3:02d}:{4:02d}:{5:02d}'"
819 ".format(*__rtc_.RTC().datetime[:6]))",
820 " del __rtc_",
821 "except:",
822 " import time as __time_",
823 " try:",
824 " print(__time_.strftime('%Y-%m-%d %H:%M:%S',"
813 # __IGNORE_WARNING_M601__ 825 # __IGNORE_WARNING_M601__
814 " __time_.localtime()))", 826 " __time_.localtime()))",
815 "except AttributeError:", 827 " except AttributeError:",
816 " tm = __time_.localtime()", 828 " tm = __time_.localtime()",
817 " print('{0:04d}-{1:02d}-{2:02d} {3:02d}:{4:02d}:{5:02d}'" 829 " print('{0:04d}-{1:02d}-{2:02d}"
830 " {3:02d}:{4:02d}:{5:02d}'"
818 ".format(tm[0], tm[1], tm[2], tm[3], tm[4], tm[5]))", 831 ".format(tm[0], tm[1], tm[2], tm[3], tm[4], tm[5]))",
819 " del tm", 832 " del tm",
833 " del __time_"
820 ]), 834 ]),
821 "del __time_"
822 ] 835 ]
823 out, err = self.execute(commands) 836 out, err = self.execute(commands)
824 if err: 837 if err:
838 if b"NotImplementedError" in err:
839 return "<unsupported> <unsupported>"
825 raise OSError(self.__shortError(err)) 840 raise OSError(self.__shortError(err))
826 return out.decode("utf-8").strip() 841 return out.decode("utf-8").strip()

eric ide

mercurial