# eric7.MicroPython.MicroPythonDeviceInterface

Module implementing an interface base class to talk to a connected MicroPython device.

### Global Attributes

None

### Classes

MicroPythonDeviceInterface | Class implementing an interface to talk to a connected MicroPython device.

### Functions

None

## MicroPythonDeviceInterface

Class implementing an interface to talk to a connected MicroPython device.

### Signals

dataReceived(data)
  emitted to send data received via the connection for further processing
executeAsyncFinished()
  emitted to indicate the end of an asynchronously executed list of commands (e.g. a script)
osdInfo(str)
  emitted when some OSD data was received from the device

### Derived from

QObject

### Class Attributes

PasteModePrompt
TracebackMarker

### Class Methods

None

### Methods

MicroPythonDeviceInterface | Constructor
connectToDevice | Public method to connect to the device.
disconnectFromDevice | Public slot to disconnect from the device.
execute | Public method to send commands to the connected device and return the result.
executeAsync | Public method to execute a series of commands over a period of time without returning any result (asynchronous execution).
handlePreferencesChanged | Public slot to handle a change of the preferences.
isConnected | Public method to get the connection status.
probeDevice | Public method to check the device is responding.
write | Public method to write data to the connected device.

### Static Methods

None

#### MicroPythonDeviceInterface (Constructor)

MicroPythonDeviceInterface(parent=None)

Constructor

parent (QObject)
  reference to the parent object

#### MicroPythonDeviceInterface.connectToDevice

connectToDevice(connection)

Public method to connect to the device.

connection (str)
  name of the connection to be used

Return:
  flag indicating success and an error message

Return Type:
  tuple of (bool, str)

Raises NotImplementedError:
  raised to indicate that this method needs to be implemented in a derived class

#### MicroPythonDeviceInterface.disconnectFromDevice

disconnectFromDevice()

Public slot to disconnect from the device.

Raises NotImplementedError:
  raised to indicate that this method needs to be implemented in a derived class

#### MicroPythonDeviceInterface.execute

execute(commands, *, mode="raw", timeout=0)

Public method to send commands to the connected device and return the result.

If no connection is available, empty results will be returned.

commands (str or list of str)
  list of commands to be executed
mode= (str)
  submit mode to be used (one of 'raw' or 'paste') (defaults to 'raw')
timeout= (int (optional))
  per command timeout in milliseconds (0 for configured default) (defaults to 0)

Return:
  tuple containing stdout and stderr output of the device

Return Type:
  tuple of (bytes, bytes)

Raises NotImplementedError:
  raised to indicate that this method needs to be implemented in a derived class
Raises ValueError:
  raised in case of an unsupported submit mode

#### MicroPythonDeviceInterface.executeAsync

executeAsync(commandsList, submitMode)

Public method to execute a series of commands over a period of time without returning any result (asynchronous execution).

commandsList (list of str)
  list of commands to be execute on the device
submitMode (str)
  mode to be used to submit the commands (one of 'raw' or 'paste')

Raises NotImplementedError:
  raised to indicate that this method needs to be implemented in a derived class
Raises ValueError:
  raised to indicate an unknown submit mode

#### MicroPythonDeviceInterface.handlePreferencesChanged

handlePreferencesChanged()

Public slot to handle a change of the preferences.

#### MicroPythonDeviceInterface.isConnected

isConnected()

Public method to get the connection status.

Return:
  flag indicating the connection status

Return Type:
  bool

Raises NotImplementedError:
  raised to indicate that this method needs to be implemented in a derived class

#### MicroPythonDeviceInterface.probeDevice

probeDevice()

Public method to check the device is responding.

If the device has not been flashed with a MicroPython firmware, the probe will fail.

Return:
  flag indicating a communicating MicroPython device

Return Type:
  bool

Raises NotImplementedError:
  raised to indicate that this method needs to be implemented in a derived class

#### MicroPythonDeviceInterface.write

write(data)

Public method to write data to the connected device.

data (bytes or bytearray)
  data to be written

Raises NotImplementedError:
  raised to indicate that this method needs to be implemented in a derived class

Up