diff -r e738a96f1e14 -r d856023fbeb0 eric7/MicroPython/MicroPythonCommandsInterface.py --- a/eric7/MicroPython/MicroPythonCommandsInterface.py Sat Jan 15 19:57:03 2022 +0100 +++ b/eric7/MicroPython/MicroPythonCommandsInterface.py Sun Jan 16 20:28:42 2022 +0100 @@ -750,6 +750,105 @@ raise OSError(self.__shortError(err)) return ast.literal_eval(out.decode("utf-8")) + def getBoardInformation(self): + """ + Public method to get some information data of the connected board. + + @return dictionary containing the determined data + @rtype dict + @exception OSError raised to indicate an issue with the device + """ + commands = [ + "res = {}", # __IGNORE_WARNING_M613__ + + "import gc as __gc_", + "__gc_.enable()", + "__gc_.collect()", + "mem_alloc = __gc_.mem_alloc()", + "mem_free = __gc_.mem_free()", + "mem_total = mem_alloc + mem_free", + "res['mem_total_kb'] = mem_total / 1024.0", + "res['mem_used_kb'] = mem_alloc / 1024.0", + "res['mem_used_pc'] = mem_alloc / mem_total * 100.0", + "res['mem_free_kb'] = mem_free / 1024.0", + "res['mem_free_pc'] = mem_free / mem_total * 100.0", + "del __gc_, mem_alloc, mem_free, mem_total", + + "import os as __os_", + "uname = __os_.uname()", + "res['sysname'] = uname.sysname", + "res['nodename'] = uname.nodename", + "res['release'] = uname.release", + "res['version'] = uname.version", + "res['machine'] = uname.machine", + + "import sys as __sys_", + "res['py_platform'] = __sys_.platform", + "res['py_version'] = __sys_.version", + "\n".join([ + "try:", + " res['mpy_name'] = __sys_.implementation.name", + "except AttributeError:", + " res['mpy_name'] = 'unknown'", + ]), + "\n".join([ + "try:", + " res['mpy_version'] = '.'.join((str(i) for i in" + " __sys_.implementation.version))", + "except AttributeError:", + " res['mpy_version'] = 'unknown'", + ]), + + "stat_ = __os_.statvfs('/flash')", + "res['flash_total_kb'] = stat_[2] * stat_[0] / 1024.0", + "res['flash_free_kb'] = stat_[3] * stat_[0] / 1024.0", + "res['flash_used_kb'] = res['flash_total_kb'] -" + " res['flash_free_kb']", + "res['flash_free_pc'] = res['flash_free_kb'] /" + " res['flash_total_kb'] * 100.0", + "res['flash_used_pc'] = res['flash_used_kb'] /" + " res['flash_total_kb'] * 100.0", + + "\n".join([ + "try:", + " import machine as __mc_", + " res['mc_frequency_mhz'] = __mc_.freq() / 1000000.0", + " res['mc_id'] = ':'.join(['{0:X}'.format(x)" + " for x in __mc_.unique_id()])", + " del __mc_", + "except ImportError:", + "\n".join([ + " try:", + " import microcontroller as __mc_", + " res['mc_frequency_mhz'] = __mc_.cpu.frequency" + " / 1000000.0", + " res['mc_temp_c'] = __mc_.cpu.temperature", + " res['mc_id'] = ':'.join(['{0:X}'.format(x)" + " for x in __mc_.cpu.uid])", + " del __mc_", + " except ImportError:", + " res['mc_frequency'] = None", + " res['mc_temp'] = None", + ]), + ]), + + "\n".join([ + "try:", + " import ulab as __ulab_", + " res['ulab'] = __ulab_.__version__", + " del __ulab_", + "except ImportError:", + " res['ulab'] = None", + ]), + + "print(res)", + "del res, stat_, __os_, __sys_", + ] + out, err = self.execute(commands) + if err: + raise OSError(self.__shortError(err)) + return ast.literal_eval(out.decode("utf-8")) + def syncTime(self, deviceType): """ Public method to set the time of the connected device to the local