public class UsbDeviceConnection
extends Object
| java.lang.Object | |
| android.hardware.usb.UsbDeviceConnection | |
该类用于向USB设备发送和接收数据和控制消息。 这个类的实例由openDevice(UsbDevice)创建。
公共方法(Public methods) |
|
|---|---|
int |
bulkTransfer(UsbEndpoint endpoint, byte[] buffer, int offset, int length, int timeout) 在给定端点上执行批量事务。 |
int |
bulkTransfer(UsbEndpoint endpoint, byte[] buffer, int length, int timeout) 在给定端点上执行批量事务。 |
boolean |
claimInterface(UsbInterface intf, boolean force) 声明独家访问 |
void |
close() 释放与设备相关的所有系统资源。 |
int |
controlTransfer(int requestType, int request, int value, int index, byte[] buffer, int offset, int length, int timeout) 对此设备执行端点零控制事务。 |
int |
controlTransfer(int requestType, int request, int value, int index, byte[] buffer, int length, int timeout) 对此设备执行端点零控制事务。 |
int |
getFileDescriptor() 返回设备的本机文件描述符,如果设备未打开,则返回-1。 |
byte[] |
getRawDescriptors() 返回设备的原始USB描述符。 |
String |
getSerial() 返回设备的序列号。 |
boolean |
releaseInterface(UsbInterface intf) 发布独家访问权限 |
UsbRequest |
requestWait() 等待 |
boolean |
setConfiguration(UsbConfiguration configuration) 设置设备当前的 |
boolean |
setInterface(UsbInterface intf) 设置当前 |
继承方法(Inherited methods) |
|
|---|---|
java.lang.Object
|
|
int bulkTransfer (UsbEndpoint endpoint, byte[] buffer, int offset, int length, int timeout)
在给定端点上执行批量事务。 传输的方向取决于端点的方向。
| 参数(Parameters) | |
|---|---|
endpoint |
UsbEndpoint: the endpoint for this transaction |
buffer |
byte: buffer for data to send or receive |
offset |
int: the index of the first byte in the buffer to send or receive |
length |
int: the length of the data to send or receive |
timeout |
int: in milliseconds |
| 返回(Returns) | |
|---|---|
int |
length of data transferred (or zero) for success, or negative value for failure |
int bulkTransfer (UsbEndpoint endpoint, byte[] buffer, int length, int timeout)
在给定端点上执行批量事务。 传输的方向取决于端点的方向。
该方法从缓冲区中的索引0开始传输数据。 要指定不同的偏移量,请使用bulkTransfer(UsbEndpoint, byte[], int, int, int) 。
| 参数(Parameters) | |
|---|---|
endpoint |
UsbEndpoint: the endpoint for this transaction |
buffer |
byte: buffer for data to send or receive |
length |
int: the length of the data to send or receive |
timeout |
int: in milliseconds |
| 返回(Returns) | |
|---|---|
int |
length of data transferred (or zero) for success, or negative value for failure |
boolean claimInterface (UsbInterface intf, boolean force)
声明独家访问UsbInterface 。 这必须在发送或接收属于接口的任何UsbEndpoint的数据之前完成。
| 参数(Parameters) | |
|---|---|
intf |
UsbInterface: the interface to claim |
force |
boolean: true to disconnect kernel driver if necessary |
| 返回(Returns) | |
|---|---|
boolean |
true if the interface was successfully claimed |
void close ()
释放与设备相关的所有系统资源。 一旦物体关闭,它不能再次使用。 客户端必须再次调用openDevice(UsbDevice)以检索新实例以重新建立与设备的通信。
int controlTransfer (int requestType,
int request,
int value,
int index,
byte[] buffer,
int offset,
int length,
int timeout)
对此设备执行端点零控制事务。 传输方向由请求类型决定。 如果requestType& USB_ENDPOINT_DIR_MASK是USB_DIR_OUT ,则传输是写入,如果是USB_DIR_IN ,则传输是读取。
| 参数(Parameters) | |
|---|---|
requestType |
int: request type for this transaction |
request |
int: request ID for this transaction |
value |
int: value field for this transaction |
index |
int: index field for this transaction |
buffer |
byte: buffer for data portion of transaction, or null if no data needs to be sent or received |
offset |
int: the index of the first byte in the buffer to send or receive |
length |
int: the length of the data to send or receive |
timeout |
int: in milliseconds |
| 返回(Returns) | |
|---|---|
int |
length of data transferred (or zero) for success, or negative value for failure |
int controlTransfer (int requestType,
int request,
int value,
int index,
byte[] buffer,
int length,
int timeout)
对此设备执行端点零控制事务。 传输方向由请求类型决定。 如果requestType& USB_ENDPOINT_DIR_MASK是USB_DIR_OUT ,则传输是写入,如果是USB_DIR_IN ,则传输是读取。
该方法从缓冲区中的索引0开始传输数据。 要指定不同的偏移量,请使用controlTransfer(int, int, int, int, byte[], int, int, int) 。
| 参数(Parameters) | |
|---|---|
requestType |
int: request type for this transaction |
request |
int: request ID for this transaction |
value |
int: value field for this transaction |
index |
int: index field for this transaction |
buffer |
byte: buffer for data portion of transaction, or null if no data needs to be sent or received |
length |
int: the length of the data to send or receive |
timeout |
int: in milliseconds |
| 返回(Returns) | |
|---|---|
int |
length of data transferred (or zero) for success, or negative value for failure |
int getFileDescriptor ()
返回设备的本机文件描述符,如果设备未打开,则返回-1。 这是为了传递给本机代码来访问设备。
| 返回(Returns) | |
|---|---|
int |
the native file descriptor |
byte[] getRawDescriptors ()
返回设备的原始USB描述符。 这可以用来访问不通过更高级别的API直接支持的描述符。
| 返回(Returns) | |
|---|---|
byte[] |
raw USB descriptors |
String getSerial ()
返回设备的序列号。 如果设备尚未打开,这将返回null。
| 返回(Returns) | |
|---|---|
String |
the device serial number |
boolean releaseInterface (UsbInterface intf)
发布对 UsbInterface独家访问权限。
| 参数(Parameters) | |
|---|---|
intf |
UsbInterface
|
| 返回(Returns) | |
|---|---|
boolean |
true if the interface was successfully released |
UsbRequest requestWait ()
等待queue(ByteBuffer, int)操作的结果请注意,这可能会返回排队在多个UsbEndpoint的请求。 当使用多个端点时, getEndpoint()和getClientData()可用于确定如何处理此功能的结果。
| 返回(Returns) | |
|---|---|
UsbRequest |
a completed USB request, or null if an error occurred |
boolean setConfiguration (UsbConfiguration configuration)
设置设备当前的 UsbConfiguration 。
| 参数(Parameters) | |
|---|---|
configuration |
UsbConfiguration
|
| 返回(Returns) | |
|---|---|
boolean |
true if the configuration was successfully set |
boolean setInterface (UsbInterface intf)
设置当前UsbInterface 。 用于在具有相同ID但不同备用设置的两个接口之间进行选择。
| 参数(Parameters) | |
|---|---|
intf |
UsbInterface
|
| 返回(Returns) | |
|---|---|
boolean |
true if the interface was successfully selected |