src/eric7/MicroPython/MicroPythonCommandsInterface.py

branch
eric7
changeset 9749
5d409223cf3f
parent 9748
df9520c864f2
child 9751
606ac0e26533
equal deleted inserted replaced
9748:df9520c864f2 9749:5d409223cf3f
183 """ 183 """
184 if self.__serial: 184 if self.__serial:
185 self.__serial.write(b"\x02") # send CTRL-B to cancel raw mode 185 self.__serial.write(b"\x02") # send CTRL-B to cancel raw mode
186 self.__serial.readUntil(b">>> ") # read until Python prompt 186 self.__serial.readUntil(b">>> ") # read until Python prompt
187 self.__serial.readAll() # read all data and discard it 187 self.__serial.readAll() # read all data and discard it
188
189 def probeDevice(self):
190 """
191 Public method to check the device is responding.
192
193 If the device has not been flashed with a MicroPython formware, the
194 probe will fail.
195
196 @return flag indicating a communicating MicroPython device
197 @rtype bool
198 """
199 if not self.__serial:
200 return False
201
202 if not self.__serial.isConnected():
203 return False
204
205 # switch on raw mode
206 self.__blockReadyRead = True
207 ok = self.__rawOn()
208 if not ok:
209 self.__blockReadyRead = False
210 return False
211
212 # switch off raw mode
213 QThread.msleep(10)
214 self.__rawOff()
215 self.__blockReadyRead = False
216
217 return True
188 218
189 def execute(self, commands): 219 def execute(self, commands):
190 """ 220 """
191 Public method to send commands to the connected device and return the 221 Public method to send commands to the connected device and return the
192 result. 222 result.
847 " del pimoroni", 877 " del pimoroni",
848 "except ImportError:", 878 "except ImportError:",
849 " res['mpy_variant'] = ''", 879 " res['mpy_variant'] = ''",
850 ] 880 ]
851 ), 881 ),
852 "stat_ = __os_.statvfs('/flash')", 882 "\n".join(
853 "res['flash_total_kb'] = stat_[2] * stat_[0] / 1024.0", 883 [
854 "res['flash_free_kb'] = stat_[3] * stat_[0] / 1024.0", 884 "try:",
855 "res['flash_used_kb'] = res['flash_total_kb'] - res['flash_free_kb']", 885 " stat_ = __os_.statvfs('/flash')",
856 "res['flash_free_pc'] = res['flash_free_kb'] /" 886 " res['flash_info_available'] = True",
857 " res['flash_total_kb'] * 100.0", 887 " res['flash_total_kb'] = stat_[2] * stat_[0] / 1024.0",
858 "res['flash_used_pc'] = res['flash_used_kb'] /" 888 " res['flash_free_kb'] = stat_[3] * stat_[0] / 1024.0",
859 " res['flash_total_kb'] * 100.0", 889 " res['flash_used_kb'] = res['flash_total_kb'] -"
890 " res['flash_free_kb']",
891 " res['flash_free_pc'] = res['flash_free_kb'] /"
892 " res['flash_total_kb'] * 100.0",
893 " res['flash_used_pc'] = res['flash_used_kb'] /"
894 " res['flash_total_kb'] * 100.0",
895 " del stat_",
896 "except AttributeError:",
897 " res['flash_info_available'] = False",
898 ]
899 ),
860 "\n".join( 900 "\n".join(
861 [ 901 [
862 "try:", 902 "try:",
863 " import machine as __mc_", 903 " import machine as __mc_",
864 " res['mc_frequency_mhz'] = __mc_.freq() / 1000000.0", 904 " if isinstance(__mc_.freq(), tuple):",
905 " res['mc_frequency_mhz'] = __mc_.freq()[0] / 1000000.0",
906 " else:",
907 " res['mc_frequency_mhz'] = __mc_.freq() / 1000000.0",
865 " res['mc_id'] = ':'.join(['{0:X}'.format(x)" 908 " res['mc_id'] = ':'.join(['{0:X}'.format(x)"
866 " for x in __mc_.unique_id()])", 909 " for x in __mc_.unique_id()])",
867 " del __mc_", 910 " del __mc_",
868 "except ImportError:", 911 "except ImportError:",
869 "\n".join( 912 "\n".join(
892 "except ImportError:", 935 "except ImportError:",
893 " res['ulab'] = None", 936 " res['ulab'] = None",
894 ] 937 ]
895 ), 938 ),
896 "print(res)", 939 "print(res)",
897 "del res, stat_, __os_, __sys_", 940 "del res, __os_, __sys_",
898 ] 941 ]
899 out, err = self.execute(commands) 942 out, err = self.execute(commands)
900 if err: 943 if err:
901 raise OSError(self.__shortError(err)) 944 raise OSError(self.__shortError(err))
902 return ast.literal_eval(out.decode("utf-8")) 945 return ast.literal_eval(out.decode("utf-8"))

eric ide

mercurial