Skip to content

Latest commit

 

History

History
376 lines (232 loc) · 12.8 KB

index.rst

File metadata and controls

376 lines (232 loc) · 12.8 KB

:pyusb.backend

usb.backend - Backend interface.

This module exports:

  • IBackend - backend interface.

Backends are Python objects which implement the IBackend interface. The easiest way to do so is inherinting from IBackend.

PyUSB already provides backends for libusb versions 0.1 and 1.0, and OpenUSB library. Backends modules included with PyUSB are required to export the get_backend() function, which returns an instance of a backend object. You can provide your own customized backend if you want to. Below you find a skeleton of a backend implementation module:

import usb.backend

class MyBackend(usb.backend.IBackend):
    pass

def get_backend():
    return MyBackend()

You can use your customized backend by passing it as the backend parameter of the usb.core.find() function. For example:

import custom_backend
import usb.core

myidVendor = 0xfffe
myidProduct = 0x0001

mybackend = custom_backend.get_backend()

dev = usb.core.find(backend = mybackend, idProduct=myidProduct,
                    idVendor=myidVendor)

For custom backends, you are not required to supply the get_backend() function, since the application code will instantiate the backend.

If you do not provide a backend to the find() function, it will use one of the defaults backend according to its internal rules. For details, consult the find() function documentation.

Submodules

libusb0/index.rst libusb1/index.rst openusb/index.rst

Package Contents

Classes

  • usb.backend.IBackend