adafruit_usb_host_midi

CircuitPython USB host driver for MIDI devices

  • Author(s): Scott Shawcroft

class adafruit_usb_host_midi.MIDI(device, timeout=None)

Stream-like MIDI device for use with adafruit_midi and similar upstream MIDI parser libraries.

Parameters:
  • device – a usb.core.Device object which implements read(endpoint, buffer) and write(endpoint,buffer)

  • timeout (float) – timeout in seconds to wait for read or write operation to succeeds. Default to None, i.e. reads and writes will block.

read(size)

Read bytes. If nbytes is specified then read at most that many bytes. Otherwise, read everything that arrives until the connection times out. Providing the number of bytes expected is highly recommended because it will be faster. If no bytes are read, return None.

Note

When no bytes are read due to a timeout, this function returns None. This matches the behavior of io.RawIOBase.read in Python 3, but differs from pyserial which returns b'' in that situation.

Returns:

Data read

Return type:

bytes or None

readinto(buf)

Read bytes into the buf. Read at most len(buf) bytes.

Returns:

number of bytes read and stored into buf

Return type:

int or None (on a non-blocking error)