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.
|
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 |
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. |
public UsbDeviceConnection(UsbDevice device)
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 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.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 bulkTransfer(UsbEndpoint endpoint, byte[] buffer, int length, int timeout)
endpoint
- the endpoint for this transactionbuffer
- buffer for data to send or receive,length
- 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()