--- a/src/eric7/MicroPython/Devices/DeviceBase.py Wed Aug 30 16:06:08 2023 +0200 +++ b/src/eric7/MicroPython/Devices/DeviceBase.py Wed Aug 30 17:23:53 2023 +0200 @@ -142,19 +142,26 @@ if connected: self._interface = self.microPython.deviceInterface() with contextlib.suppress(OSError): - self._deviceData = self.__getDeviceData() - self._deviceData["local_mip"] = ( - not self._deviceData["mip"] - and not self._deviceData["upip"] - and not self.hasCircuitPython() - ) - self._deviceData["wifi"], self._deviceData["wifi_type"] = self.hasWifi() - self._deviceData["bluetooth"] = self.hasBluetooth() - ( - self._deviceData["ethernet"], - self._deviceData["ethernet_type"], - ) = self.hasEthernet() - self._deviceData["ntp"] = self.hasNetworkTime() + data = self.__getDeviceData() + if "mpy_name" in data: + self._deviceData = data + self._deviceData["local_mip"] = ( + not self._deviceData["mip"] + and not self._deviceData["upip"] + and not self.hasCircuitPython() + ) + ( + self._deviceData["wifi"], + self._deviceData["wifi_type"], + ) = self.hasWifi() + self._deviceData["bluetooth"] = self.hasBluetooth() + ( + self._deviceData["ethernet"], + self._deviceData["ethernet_type"], + ) = self.hasEthernet() + self._deviceData["ntp"] = self.hasNetworkTime() + else: + self._deviceData = {} else: self._interface = None @@ -225,10 +232,13 @@ @return flag indicating CircuitPython @rtype bool """ - return ( - self.checkDeviceData() - and self._deviceData["mpy_name"].lower() == "circuitpython" - ) + try: + return ( + self.checkDeviceData() + and self._deviceData["mpy_name"].lower() == "circuitpython" + ) + except KeyError: + return False def submitMode(self): """ @@ -1126,8 +1136,8 @@ @rtype dict @exception OSError raised to indicate an issue with the device """ - command = """ -def get_board_info(): + commands = [ # needs to be splitted for boards with low memory + """def get_board_info(): res = {} import gc @@ -1143,6 +1153,14 @@ res['mem_free_pc'] = mem_free / mem_total * 100.0 del gc, mem_alloc, mem_free, mem_total + return res + +print(get_board_info()) +del get_board_info +""", + """def get_board_info(): + res = {} + try: import os uname = os.uname() @@ -1159,6 +1177,14 @@ res['version'] = sys.version.split(';', 1)[-1].strip() res['machine'] = sys.implementation._machine + return res + +print(get_board_info()) +del get_board_info +""", + """def get_board_info(): + res = {} + import sys res['py_platform'] = sys.platform res['py_version'] = sys.version @@ -1186,7 +1212,16 @@ res['mpy_variant_info'] = '' res['mpy_variant_version'] = '' + return res + +print(get_board_info()) +del get_board_info +""", + """def get_board_info(): + res = {} + try: + import os stat_ = os.statvfs('/flash') res['flash_info_available'] = True res['flash_total_kb'] = stat_[2] * stat_[0] / 1024.0 @@ -1197,6 +1232,14 @@ except (AttributeError, OSError): res['flash_info_available'] = False + return res + +print(get_board_info()) +del get_board_info +""", + """def get_board_info(): + res = {} + try: import machine as mc if isinstance(mc.freq(), tuple): @@ -1216,6 +1259,14 @@ if 'mc_id' in res: res['mc_id'] = ':'.join('{0:02X}'.format(x) for x in res['mc_id']) + return res + +print(get_board_info()) +del get_board_info +""", + """def get_board_info(): + res = {} + try: import ulab res['ulab'] = ulab.__version__ @@ -1226,11 +1277,15 @@ print(get_board_info()) del get_board_info -""" - out, err = self.executeCommands(command, mode=self._submitMode) - if err: - raise OSError(self._shortError(err)) - return ast.literal_eval(out.decode("utf-8")) +""", + ] + res = {} + for command in commands: + out, err = self.executeCommands(command, mode=self._submitMode) + if err: + raise OSError(self._shortError(err)) + res.update(ast.literal_eval(out.decode("utf-8"))) + return res def getModules(self): """