adb_shell.transport.usb_transport module
A class for creating a USB connection with the device and sending and receiving data.
Warning
USB support is an experimental feature.
-
UsbTransport._timeout()
- adb_shell.transport.usb_transport.DEFAULT_TIMEOUT_S = 10
Default timeout
- class adb_shell.transport.usb_transport.UsbTransport(device, setting, usb_info=None, default_transport_timeout_s=None)[source]
Bases:
BaseTransport
USB communication object. Not thread-safe.
Handles reading and writing over USB with the proper endpoints, exceptions, and interface claiming.
- Parameters:
device (usb1.USBDevice) – libusb_device to connect to.
setting (usb1.USBInterfaceSetting) – libusb setting with the correct endpoints to communicate with.
usb_info (TODO, None) – String describing the usb path/serial/device, for debugging.
default_transport_timeout_s (TODO, None) – Timeout in seconds for all I/O.
- _default_transport_timeout_s
Timeout in seconds for all I/O.
- Type:
TODO, None
- _device
libusb_device to connect to.
- Type:
TODO
- _transport
TODO
- Type:
TODO
- _interface_number
TODO
- Type:
TODO
- _max_read_packet_len
TODO
- Type:
TODO
- _read_endpoint
TODO
- Type:
TODO
- _setting
libusb setting with the correct endpoints to communicate with.
- Type:
TODO
- _usb_info
String describing the usb path/serial/device, for debugging.
- Type:
TODO
- _write_endpoint
TODO
- Type:
TODO, None
- _HANDLE_CACHE = <WeakValueDictionary>
- _HANDLE_CACHE_LOCK = <unlocked _thread.lock object>
- _abc_impl = <_abc._abc_data object>
- classmethod _find(setting_matcher, port_path=None, serial=None, default_transport_timeout_s=None)[source]
Gets the first device that matches according to the keyword args.
- Parameters:
setting_matcher (TODO) – TODO
port_path (TODO, None) – TODO
serial (TODO, None) – TODO
default_transport_timeout_s (TODO, None) – TODO
- Returns:
TODO
- Return type:
TODO
- classmethod _find_and_open(setting_matcher, port_path=None, serial=None, default_transport_timeout_s=None)[source]
TODO
- Parameters:
setting_matcher (TODO) – TODO
port_path (TODO, None) – TODO
serial (TODO, None) – TODO
default_transport_timeout_s (TODO, None) – TODO
- Returns:
dev – TODO
- Return type:
TODO
- classmethod _find_devices(setting_matcher, device_matcher=None, usb_info='', default_transport_timeout_s=None)[source]
_find and yield the devices that match.
- Parameters:
setting_matcher (TODO) – Function that returns the setting to use given a
usb1.USBDevice
, orNone
if the device doesn’t have a valid setting.device_matcher (TODO, None) – Function that returns
True
if the givenUsbTransport
is valid.None
to match any device.usb_info (str) – Info string describing device(s).
default_transport_timeout_s (TODO, None) – Default timeout of commands in seconds.
- Yields:
TODO – UsbTransport instances
- classmethod _find_first(setting_matcher, device_matcher=None, usb_info='', default_transport_timeout_s=None)[source]
Find and return the first matching device.
- Parameters:
setting_matcher (TODO) – Function that returns the setting to use given a
usb1.USBDevice
, orNone
if the device doesn’t have a valid setting.device_matcher (TODO) – Function that returns
True
if the givenUsbTransport
is valid.None
to match any device.usb_info (str) – Info string describing device(s).
default_transport_timeout_s (TODO, None) – Default timeout of commands in seconds.
- Returns:
An instance of UsbTransport
- Return type:
TODO
- Raises:
adb_shell.exceptions.DeviceNotFoundError – Raised if the device is not available.
- classmethod _port_path_matcher(port_path)[source]
Returns a device matcher for the given port path.
- Parameters:
port_path (TODO) – TODO
- Returns:
TODO
- Return type:
function
- classmethod _serial_matcher(serial)[source]
Returns a device matcher for the given serial.
- Parameters:
serial (TODO) – TODO
- Returns:
TODO
- Return type:
function
- bulk_read(numbytes, transport_timeout_s=None)[source]
Receive data from the USB device.
- Parameters:
numbytes (int) – The maximum amount of data to be received
transport_timeout_s (float, None) – When the timeout argument is omitted,
select.select
blocks until at least one file descriptor is ready. A time-out value of zero specifies a poll and never blocks.
- Returns:
The received data
- Return type:
bytes
- Raises:
adb_shell.exceptions.UsbReadFailedError – Could not receive data
- bulk_write(data, transport_timeout_s=None)[source]
Send data to the USB device.
- Parameters:
data (bytes) – The data to be sent
transport_timeout_s (float, None) – When the timeout argument is omitted,
select.select
blocks until at least one file descriptor is ready. A time-out value of zero specifies a poll and never blocks.
- Returns:
The number of bytes sent
- Return type:
int
- Raises:
adb_shell.exceptions.UsbWriteFailedError – This transport has been closed, probably due to another being opened
adb_shell.exceptions.UsbWriteFailedError – Could not send data
- connect(transport_timeout_s=None)[source]
Create a USB connection to the device.
- Parameters:
transport_timeout_s (float, None) – Set the timeout on the USB instance
- classmethod find_adb(serial=None, port_path=None, default_transport_timeout_s=None)[source]
TODO
- Parameters:
serial (TODO) – TODO
port_path (TODO) – TODO
default_transport_timeout_s (TODO, None) – Default timeout of commands in seconds.
- Returns:
TODO
- Return type:
- classmethod find_all_adb_devices(default_transport_timeout_s=None)[source]
Find all ADB devices attached via USB.
- Parameters:
default_transport_timeout_s (TODO, None) – Default timeout of commands in seconds.
- Returns:
A generator which yields each ADB device attached via USB.
- Return type:
generator
- property port_path
TODO
- Returns:
TODO
- Return type:
TODO
- property serial_number
TODO
- Returns:
TODO
- Return type:
TODO
- property usb_info
TODO
- Returns:
TODO
- Return type:
TODO