eric7.MicroPython.Devices.DeviceBase

Module implementing some utility functions and the MicroPythonDevice base class.

Global Attributes

None

Classes

BaseDevice Base class for the more specific MicroPython devices.

Functions

None


BaseDevice

Base class for the more specific MicroPython devices.

It includes a list of commands for general use on the various boards. If a board needs special treatment, the command should be overwritten in the board specific subclass. Commands are provided to perform operations on the file system of a connected MicroPython device, for getting and setting the time on the board and getting board related data. Supported file system commands are:

Supported non file system commands are:

Derived from

QObject

Class Attributes

None

Class Methods

None

Methods

BaseDevice Constructor
__getDeviceData Private method to get some essential data for the connected board.
_getSetTimeCode Protected method to get the device code to set the time.
_shortError Protected method to create a shortened error message.
addDeviceMenuEntries Public method to add device specific entries to the given menu.
canRunScript Public method to determine, if a script can be executed.
canStartFileManager Public method to determine, if a File Manager can be started.
canStartPlotter Public method to determine, if a Plotter can be started.
canStartRepl Public method to determine, if a REPL can be started.
cd Public method to change the current directory on the connected device.
checkDeviceData Public method to check the validity of the device data determined during connecting the device.
deviceName Public method to get the name of the device.
downloadFirmware Public method to download the device firmware.
fileSystemInfo Public method to obtain information about the currently mounted file systems.
forceInterrupt Public method to determine the need for an interrupt when opening the serial connection.
get Public method to copy a file from the connected device.
getBoardInformation Public method to get some information data of the connected board.
getData Public method to read data from the connected device.
getDeviceData Public method to get a copy of the determined device data.
getDeviceType Public method to get the device type.
getDocumentationUrl Public method to get the device documentation URL.
getDownloadMenuEntries Public method to retrieve the entries for the downloads menu.
getFirmwareUrl Public method to get the device firmware download URL.
getModules Public method to show a list of modules built into the firmware.
getTime Public method to get the current time of the device.
getWorkspace Public method to get the workspace directory.
handleDataFlood Public slot handling a data floof from the device.
hasCircuitPython Public method to check, if the connected device is flashed with CircuitPython.
hasDocumentationUrl Public method to check, if the device has a configured documentation URL.
hasFirmwareUrl Public method to check, if the device has a configured firmware download URL.
hasFlashMenuEntry Public method to check, if the device has its own flash menu entry.
hasTimeCommands Public method to check, if the device supports time commands.
lls Public method to get a long directory listing of the connected device including meta data.
ls Public method to get a directory listing of the connected device.
mkdir Public method to create a new directory.
put Public method to copy a local file to the connected device.
putData Public method to write the given data to the connected device.
pwd Public method to get the current directory of the connected device.
rm Public method to remove a file from the connected device.
rmdir Public method to remove a directory.
rmrf Public method to remove a file or directory recursively.
runScript Public method to run the given Python script.
selectDeviceDirectory Public method to select the device directory from a list of detected ones.
sendCommands Public method to send a list of commands to the device.
setButtons Public method to enable the supported action buttons.
setConnected Public method to set the connection state.
setFileManager Public method to set the File Manager status and dependent status.
setPlotter Public method to set the Plotter status and dependent status.
setRepl Public method to set the REPL status and dependent status.
supportsLocalFileAccess Public method to indicate file access via a local directory.
syncTime Public method to set the time of the connected device to the local computer's time.

Static Methods

None

BaseDevice (Constructor)

BaseDevice(microPythonWidget, deviceType, parent=None)

Constructor

microPythonWidget (MicroPythonWidget)
reference to the main MicroPython widget
deviceType (str)
device type assigned to this device interface
parent (QObject)
reference to the parent object

BaseDevice.__getDeviceData

__getDeviceData()

Private method to get some essential data for the connected board.

Return:
dictionary containing the determined data
Return Type:
dict
Raises OSError:
raised to indicate an issue with the device

BaseDevice._getSetTimeCode

_getSetTimeCode()

Protected method to get the device code to set the time.

Note: This method must be implemented in the various device specific subclasses.

Return:
code to be executed on the connected device to set the time
Return Type:
str

BaseDevice._shortError

_shortError(error)

Protected method to create a shortened error message.

error (bytes)
verbose error message
Return:
shortened error message
Return Type:
str

BaseDevice.addDeviceMenuEntries

addDeviceMenuEntries(menu)

Public method to add device specific entries to the given menu.

menu (QMenu)
reference to the context menu

BaseDevice.canRunScript

canRunScript()

Public method to determine, if a script can be executed.

Return:
tuple containing a flag indicating it is safe to start a Plotter and a reason why it cannot.
Return Type:
tuple of (bool, str)

BaseDevice.canStartFileManager

canStartFileManager()

Public method to determine, if a File Manager can be started.

Return:
tuple containing a flag indicating it is safe to start a File Manager and a reason why it cannot.
Return Type:
tuple of (bool, str)

BaseDevice.canStartPlotter

canStartPlotter()

Public method to determine, if a Plotter can be started.

Return:
tuple containing a flag indicating it is safe to start a Plotter and a reason why it cannot.
Return Type:
tuple of (bool, str)

BaseDevice.canStartRepl

canStartRepl()

Public method to determine, if a REPL can be started.

Return:
tuple containing a flag indicating it is safe to start a REPL and a reason why it cannot.
Return Type:
tuple of (bool, str)

BaseDevice.cd

cd(dirname)

Public method to change the current directory on the connected device.

dirname (str)
directory to change to
Raises OSError:
raised to indicate an issue with the device

BaseDevice.checkDeviceData

checkDeviceData(quiet=True)

Public method to check the validity of the device data determined during connecting the device.

quiet (bool (optional))
flag indicating to not show an info message, if the data is not available (defaults to True)
Return:
flag indicating valid device data
Return Type:
bool

BaseDevice.deviceName

deviceName()

Public method to get the name of the device.

Return:
name of the device
Return Type:
str

BaseDevice.downloadFirmware

downloadFirmware()

Public method to download the device firmware.

BaseDevice.fileSystemInfo

fileSystemInfo()

Public method to obtain information about the currently mounted file systems.

Return:
tuple of tuples containing the file system name, the total size, the used size and the free size
Return Type:
tuple of tuples of (str, int, int, int)
Raises OSError:
raised to indicate an issue with the device

BaseDevice.forceInterrupt

forceInterrupt()

Public method to determine the need for an interrupt when opening the serial connection.

Return:
flag indicating an interrupt is needed
Return Type:
bool

BaseDevice.get

get(deviceFileName, hostFileName=None)

Public method to copy a file from the connected device.

deviceFileName (str)
name of the file to copy
hostFileName (str)
name of the file to copy to
Return:
flag indicating success
Return Type:
bool
Raises OSError:
raised to indicate an issue with the device

BaseDevice.getBoardInformation

getBoardInformation()

Public method to get some information data of the connected board.

Return:
dictionary containing the determined data
Return Type:
dict
Raises OSError:
raised to indicate an issue with the device

BaseDevice.getData

getData(deviceFileName)

Public method to read data from the connected device.

deviceFileName (str)
name of the file to read from
Return:
data read from the device
Return Type:
bytes
Raises OSError:
raised to indicate an issue with the device

BaseDevice.getDeviceData

getDeviceData()

Public method to get a copy of the determined device data.

Return:
dictionary containing the essential device data
Return Type:
dict

BaseDevice.getDeviceType

getDeviceType()

Public method to get the device type.

Return:
type of the device
Return Type:
str

BaseDevice.getDocumentationUrl

getDocumentationUrl()

Public method to get the device documentation URL.

Return:
documentation URL of the device
Return Type:
str

BaseDevice.getDownloadMenuEntries

getDownloadMenuEntries()

Public method to retrieve the entries for the downloads menu.

Return:
list of tuples with menu text and URL to be opened for each entry
Return Type:
list of tuple of (str, str)

BaseDevice.getFirmwareUrl

getFirmwareUrl()

Public method to get the device firmware download URL.

Return:
firmware download URL of the device
Return Type:
str

BaseDevice.getModules

getModules()

Public method to show a list of modules built into the firmware.

Return:
list of builtin modules
Return Type:
list of str
Raises OSError:
raised to indicate an issue with the device

BaseDevice.getTime

getTime()

Public method to get the current time of the device.

Return:
time of the device
Return Type:
str
Raises OSError:
raised to indicate an issue with the device

BaseDevice.getWorkspace

getWorkspace()

Public method to get the workspace directory.

Return:
workspace directory used for saving files
Return Type:
str

BaseDevice.handleDataFlood

handleDataFlood()

Public slot handling a data floof from the device.

BaseDevice.hasCircuitPython

hasCircuitPython()

Public method to check, if the connected device is flashed with CircuitPython.

Return:
flag indicating CircuitPython
Return Type:
bool

BaseDevice.hasDocumentationUrl

hasDocumentationUrl()

Public method to check, if the device has a configured documentation URL.

Return:
flag indicating a configured documentation URL
Return Type:
bool

BaseDevice.hasFirmwareUrl

hasFirmwareUrl()

Public method to check, if the device has a configured firmware download URL.

Return:
flag indicating a configured firmware download URL
Return Type:
bool

BaseDevice.hasFlashMenuEntry

hasFlashMenuEntry()

Public method to check, if the device has its own flash menu entry.

Return:
flag indicating a specific flash menu entry
Return Type:
bool

BaseDevice.hasTimeCommands

hasTimeCommands()

Public method to check, if the device supports time commands.

The default returns True.

Return:
flag indicating support for time commands
Return Type:
bool

BaseDevice.lls

lls(dirname="", fullstat=False, showHidden=False)

Public method to get a long directory listing of the connected device including meta data.

dirname (str)
name of the directory to be listed
fullstat (bool)
flag indicating to return the full stat() tuple
showHidden (bool)
flag indicating to show hidden files as well
Return:
list containing the directory listing with tuple entries of the name and and a tuple of mode, size and time (if fullstat is false) or the complete stat() tuple. 'None' is returned in case the directory doesn't exist.
Return Type:
tuple of (str, tuple)
Raises OSError:
raised to indicate an issue with the device

BaseDevice.ls

ls(dirname="")

Public method to get a directory listing of the connected device.

dirname (str)
name of the directory to be listed
Return:
tuple containg the directory listing
Return Type:
tuple of str
Raises OSError:
raised to indicate an issue with the device

BaseDevice.mkdir

mkdir(dirname)

Public method to create a new directory.

dirname (str)
name of the directory to create
Raises OSError:
raised to indicate an issue with the device

BaseDevice.put

put(hostFileName, deviceFileName=None)

Public method to copy a local file to the connected device.

hostFileName (str)
name of the file to be copied
deviceFileName (str)
name of the file to copy to
Return:
flag indicating success
Return Type:
bool
Raises OSError:
raised to indicate an issue with the device

BaseDevice.putData

putData(deviceFileName, content)

Public method to write the given data to the connected device.

deviceFileName (str)
name of the file to write to
content (bytes)
data to write
Return:
flag indicating success
Return Type:
bool
Raises OSError:
raised to indicate an issue with the device

BaseDevice.pwd

pwd()

Public method to get the current directory of the connected device.

Return:
current directory
Return Type:
str
Raises OSError:
raised to indicate an issue with the device

BaseDevice.rm

rm(filename)

Public method to remove a file from the connected device.

filename (str)
name of the file to be removed
Raises OSError:
raised to indicate an issue with the device

BaseDevice.rmdir

rmdir(dirname)

Public method to remove a directory.

dirname (str)
name of the directory to be removed
Raises OSError:
raised to indicate an issue with the device

BaseDevice.rmrf

rmrf(name, recursive=False, force=False)

Public method to remove a file or directory recursively.

name (str)
of the file or directory to remove
recursive (bool)
flag indicating a recursive deletion
force (bool)
flag indicating to ignore errors
Return:
flag indicating success
Return Type:
bool
Raises OSError:
raised to indicate an issue with the device

BaseDevice.runScript

runScript(script)

Public method to run the given Python script.

script (str)
script to be executed

BaseDevice.selectDeviceDirectory

selectDeviceDirectory(deviceDirectories)

Public method to select the device directory from a list of detected ones.

deviceDirectories (list of str)
list of directories to select from
Return:
selected directory or an empty string
Return Type:
str

BaseDevice.sendCommands

sendCommands(commandsList)

Public method to send a list of commands to the device.

commandsList (list of str)
list of commands to be sent to the device

BaseDevice.setButtons

setButtons()

Public method to enable the supported action buttons.

BaseDevice.setConnected

setConnected(connected)

Public method to set the connection state.

Note: This method can be overwritten to perform actions upon connect or disconnect of the device.

connected (bool)
connection state

BaseDevice.setFileManager

setFileManager(on)

Public method to set the File Manager status and dependent status.

on (bool)
flag indicating the active status

BaseDevice.setPlotter

setPlotter(on)

Public method to set the Plotter status and dependent status.

on (bool)
flag indicating the active status

BaseDevice.setRepl

setRepl(on)

Public method to set the REPL status and dependent status.

on (bool)
flag indicating the active status

BaseDevice.supportsLocalFileAccess

supportsLocalFileAccess()

Public method to indicate file access via a local directory.

Return:
flag indicating file access via local directory
Return Type:
bool

BaseDevice.syncTime

syncTime(deviceType, hasCPy=False)

Public method to set the time of the connected device to the local computer's time.

deviceType (str)
type of board to sync time to
hasCPy (bool)
flag indicating that the device has CircuitPython loadede (defaults to False)
Raises OSError:
raised to indicate an issue with the device
Up