public class UsbDeviceConnection extends Object
UsbManager.openDevice(android.hardware.usb.UsbDevice)
.Constructor and Description |
---|
UsbDeviceConnection(UsbDevice device)
UsbDevice should only be instantiated by UsbService implementation
|
Modifier and Type | Method and Description |
---|---|
int |
bulkTransfer(UsbEndpoint endpoint,
byte[] buffer,
int length,
int timeout)
Performs a bulk transaction on the given endpoint.
|
int |
bulkTransfer(UsbEndpoint endpoint,
byte[] buffer,
int offset,
int length,
int timeout)
Performs a bulk transaction on the given endpoint.
|
boolean |
claimInterface(UsbInterface intf,
boolean force)
Claims exclusive access to a
UsbInterface . |
void |
close()
Releases all system resources related to the device.
|
int |
controlTransfer(int requestType,
int request,
int value,
int index,
byte[] buffer,
int length,
int timeout)
Performs a control transaction on endpoint zero for this device.
|
int |
controlTransfer(int requestType,
int request,
int value,
int index,
byte[] buffer,
int offset,
int length,
int timeout)
Performs a control transaction on endpoint zero for this device.
|
Context |
getContext() |
int |
getFileDescriptor()
Returns the native file descriptor for the device, or
-1 if the device is not opened.
|
byte[] |
getRawDescriptors()
Returns the raw USB descriptors for the device.
|
String |
getSerial()
Returns the serial number for the device.
|
boolean |
releaseInterface(UsbInterface intf)
Releases exclusive access to a
UsbInterface . |
UsbRequest |
requestWait()
Waits for the result of a
UsbRequest.queue(java.nio.ByteBuffer, int) operation
Note that this may return requests queued on multiple
UsbEndpoint s. |
boolean |
setConfiguration(UsbConfiguration configuration)
Sets the device's current
UsbConfiguration . |
boolean |
setInterface(UsbInterface intf)
Sets the current
UsbInterface . |
public UsbDeviceConnection(UsbDevice device)
public Context getContext()
public void close()
UsbManager.openDevice(android.hardware.usb.UsbDevice)
again
to retrieve a new instance to reestablish communication with the device.public int getFileDescriptor()
public byte[] getRawDescriptors()
public boolean claimInterface(UsbInterface intf, boolean force)
UsbInterface
.
This must be done before sending or receiving data on any
UsbEndpoint
s belonging to the interface.intf
- the interface to claimforce
- true to disconnect kernel driver if necessarypublic boolean releaseInterface(UsbInterface intf)
UsbInterface
.public boolean setInterface(UsbInterface intf)
UsbInterface
.
Used to select between two interfaces with the same ID but different alternate setting.public boolean setConfiguration(UsbConfiguration configuration)
UsbConfiguration
.public int controlTransfer(int requestType, int request, int value, int index, byte[] buffer, int length, int timeout)
UsbConstants.USB_ENDPOINT_DIR_MASK
is
UsbConstants.USB_DIR_OUT
, then the transfer is a write,
and if it is UsbConstants.USB_DIR_IN
, then the transfer
is a read.
This method transfers data starting from index 0 in the buffer.
To specify a different offset, use
controlTransfer(int, int, int, int, byte[], int, int, int)
.
requestType
- request type for this transactionrequest
- request ID for this transactionvalue
- value field for this transactionindex
- index field for this transactionbuffer
- buffer for data portion of transaction,
or null if no data needs to be sent or receivedlength
- the length of the data to send or receivetimeout
- in millisecondspublic int controlTransfer(int requestType, int request, int value, int index, byte[] buffer, int offset, int length, int timeout)
UsbConstants.USB_ENDPOINT_DIR_MASK
is
UsbConstants.USB_DIR_OUT
, then the transfer is a write,
and if it is UsbConstants.USB_DIR_IN
, then the transfer
is a read.requestType
- request type for this transactionrequest
- request ID for this transactionvalue
- value field for this transactionindex
- index field for this transactionbuffer
- buffer for data portion of transaction,
or null if no data needs to be sent or receivedoffset
- the index of the first byte in the buffer to send or receivelength
- the length of the data to send or receivetimeout
- in millisecondspublic int bulkTransfer(UsbEndpoint endpoint, byte[] buffer, int length, int timeout)
This method transfers data starting from index 0 in the buffer.
To specify a different offset, use
bulkTransfer(UsbEndpoint, byte[], int, int, int)
.
endpoint
- the endpoint for this transactionbuffer
- buffer for data to send or receivelength
- the length of the data to send or receivetimeout
- in millisecondspublic int bulkTransfer(UsbEndpoint endpoint, byte[] buffer, int offset, int length, int timeout)
endpoint
- the endpoint for this transactionbuffer
- buffer for data to send or receiveoffset
- the index of the first byte in the buffer to send or receivelength
- the length of the data to send or receivetimeout
- in millisecondspublic UsbRequest requestWait()
UsbRequest.queue(java.nio.ByteBuffer, int)
operation
Note that this may return requests queued on multiple
UsbEndpoint
s.
When multiple endpoints are in use, UsbRequest.getEndpoint()
and
UsbRequest.getClientData()
can be useful in determining
how to process the result of this function.public String getSerial()