Most visited

Recently visited

Added in API level 12

UsbDeviceConnection

public class UsbDeviceConnection
extends Object

java.lang.Object
   ↳ android.hardware.usb.UsbDeviceConnection


该类用于向USB设备发送和接收数据和控制消息。 这个类的实例由openDevice(UsbDevice)创建。

Summary

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)

声明独家访问 UsbInterface

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)

发布独家访问权限 UsbInterface

UsbRequest requestWait()

等待 queue(ByteBuffer, int)操作的结果请注意,这可能会返回排队在多个 UsbEndpoint的请求。

boolean setConfiguration(UsbConfiguration configuration)

设置设备当前的 UsbConfiguration

boolean setInterface(UsbInterface intf)

设置当前 UsbInterface

Inherited methods

From class java.lang.Object

Public methods

bulkTransfer

Added in API level 18
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

bulkTransfer

Added in API level 12
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

claimInterface

Added in API level 12
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

close

Added in API level 12
void close ()

释放与设备相关的所有系统资源。 一旦物体关闭,它不能再次使用。 客户端必须再次调用openDevice(UsbDevice)以检索新实例以重新建立与设备的通信。

controlTransfer

Added in API level 18
int controlTransfer (int requestType, 
                int request, 
                int value, 
                int index, 
                byte[] buffer, 
                int offset, 
                int length, 
                int timeout)

对此设备执行端点零控制事务。 传输方向由请求类型决定。 如果requestType& USB_ENDPOINT_DIR_MASKUSB_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

controlTransfer

Added in API level 12
int controlTransfer (int requestType, 
                int request, 
                int value, 
                int index, 
                byte[] buffer, 
                int length, 
                int timeout)

对此设备执行端点零控制事务。 传输方向由请求类型决定。 如果requestType& USB_ENDPOINT_DIR_MASKUSB_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

getFileDescriptor

Added in API level 12
int getFileDescriptor ()

返回设备的本机文件描述符,如果设备未打开,则返回-1。 这是为了传递给本机代码来访问设备。

Returns
int the native file descriptor

getRawDescriptors

Added in API level 13
byte[] getRawDescriptors ()

返回设备的原始USB描述符。 这可以用来访问不通过更高级别的API直接支持的描述符。

Returns
byte[] raw USB descriptors

getSerial

Added in API level 12
String getSerial ()

返回设备的序列号。 如果设备尚未打开,这将返回null。

Returns
String the device serial number

releaseInterface

Added in API level 12
boolean releaseInterface (UsbInterface intf)

发布对 UsbInterface独家访问权限。

Parameters
intf UsbInterface
Returns
boolean true if the interface was successfully released

requestWait

Added in API level 12
UsbRequest requestWait ()

等待queue(ByteBuffer, int)操作的结果请注意,这可能会返回排队在多个UsbEndpoint的请求。 当使用多个端点时, getEndpoint()getClientData()可用于确定如何处理此功能的结果。

Returns
UsbRequest a completed USB request, or null if an error occurred

setConfiguration

Added in API level 21
boolean setConfiguration (UsbConfiguration configuration)

设置设备当前的 UsbConfiguration

Parameters
configuration UsbConfiguration
Returns
boolean true if the configuration was successfully set

setInterface

Added in API level 21
boolean setInterface (UsbInterface intf)

设置当前UsbInterface 用于在具有相同ID但不同备用设置的两个接口之间进行选择。

Parameters
intf UsbInterface
Returns
boolean true if the interface was successfully selected

Hooray!