public class USBDevicePipe extends Object
Applications can get device descriptors from USBDevice to operate the USB devices.
SystemCapability.Usb#USB_MANAGER| 构造器 | 说明 |
|---|---|
USBDevicePipe(USBDevice device) |
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
int |
bulkTransfer(USBEndpoint epObj,
byte[] buffer,
int length,
int timeout) |
Performs bulk data transfer on a specified endpoint.
|
int |
bulkTransfer(USBEndpoint epObj,
byte[] buffer,
int offset,
int length,
int timeout) |
Performs bulk data transfer on a specified endpoint.
|
boolean |
claimInterface(USBInterface interfaceObj,
boolean force) |
Claims that a specified interface is exclusively occupied.
|
void |
close() |
Closes the
USBDevicePipeAdapter. |
int |
controlTransfer(int requestType,
int request,
int value,
int index,
byte[] buffer,
int length,
int timeout) |
Performs control message transfer on endpoint zero.
|
int |
controlTransfer(int requestType,
int request,
int value,
int index,
byte[] buffer,
int offset,
int length,
int timeout) |
Performs control message transfer on endpoint zero.
|
int |
getFileDescriptor() |
Get the file descriptor.
|
byte[] |
getRawDescriptors() |
Get the original USB descriptors.
|
String |
getSerial() |
Get the serial number, in string.
|
boolean |
openByInt(String name,
int fd) |
Performs an open process on the file descriptor.
|
boolean |
releaseInterface(USBInterface interfaceObj) |
Claims that a specified interface is released.
|
USBRequest |
requestWait() |
Waits for the result returned by the
USBRequest.queue(java.nio.ByteBuffer) method. |
USBRequest |
requestWait(long timeout) |
Waits for the result returned by the
USBRequest.queue(java.nio.ByteBuffer) method. |
boolean |
setConfiguration(USBConfig config) |
Sets the current USB configuration.
|
boolean |
setInterface(USBInterface interfaceObj) |
Sets the current USB interface.
|
public final USBDevice device
USBDevice.public USBDevicePipe(USBDevice device)
public int bulkTransfer(USBEndpoint epObj, byte[] buffer, int length, int timeout)
epObj - the endpoint instance.buffer - Indicates the buffer for bulk data transfer.length - Indicates the length of the data to transfer.timeout - Indicates the transfer timeout period, in millisecond. The value 0 indicates that the
transfer never times out.0 if the data transfer is successful; returns a
negative value otherwise.public int bulkTransfer(USBEndpoint epObj, byte[] buffer, int offset, int length, int timeout)
epObj - the endpoint instance.buffer - Indicates the buffer for bulk data transfer.offset - Indicates the offset from first byte in the buffer.length - Indicates the length of the data to transfer.timeout - Indicates the transfer timeout period, in millisecond. The value 0 indicates that the
transfer never times out.0 if the data transfer is successful; returns a negative
value otherwise.public boolean claimInterface(USBInterface interfaceObj, boolean force)
interfaceObj interface.interfaceObj - Indicates the interface to be exclusively occupied.force - Indicates whether the kernel driver is disconnected. The value true indicates that the
kernel driver is disconnected. The value false indicates that the kernel driver is connectedtrue if the claim is successful; returns false otherwise.public void close()
USBDevicePipeAdapter.public int controlTransfer(int requestType,
int request,
int value,
int index,
byte[] buffer,
int offset,
int length,
int timeout)
requestType - Indicates the type of request initiated for control message transfer. For details,
see USB protocol specifications. If the most significant bit is 1, data is written from the host. If the most
significant bit is 0, data is written into the host.request - Indicates the request ID.value - Indicates the value of the transfer.index - Indicates the index of the transfer.buffer - Indicates the buffer from which data is to be transferred.offset - Indicates the offset address starting from 0 in the data buffer.length - Indicates the length of the data to transfer.timeout - Indicates the transfer timeout period, in millisecond.0 if the transfer fails.public int controlTransfer(int requestType,
int request,
int value,
int index,
byte[] buffer,
int length,
int timeout)
requestType - Indicates the type of request initiated for control message transfer. For details, see USB
protocol specifications. If the most significant bit is 1, data is written from the host. If the most
significant bit is 0, data is written into the host.request - Indicates the request ID.value - Indicates the value of the transfer.index - Indicates the index of the transfer.buffer - Indicates the buffer from which data is to be transferred.length - Indicates the length of the data to transfer.timeout - Indicates the transfer timeout period, in millisecond.0 if the transfer fails.public int getFileDescriptor()
public byte[] getRawDescriptors()
public String getSerial()
public boolean releaseInterface(USBInterface interfaceObj)
interfaceObj - Indicates the interface to release.true if the release is successful; returns false otherwise.public USBRequest requestWait(long timeout) throws TimeoutException
USBRequest.queue(java.nio.ByteBuffer) method. This is an
asynchronous
method call. If the operation times out, a timeout exception is thrown.timeout - Indicates the timeout period, in milliseconds. The value 0 indicates no waiting.USBRequest object.TimeoutException - Throws this exception if the specified timeout elapses.public USBRequest requestWait()
USBRequest.queue(java.nio.ByteBuffer) method.USBRequest object.public boolean setConfiguration(USBConfig config)
config - The config instance.true if the setting is successful; returns false otherwise.public boolean setInterface(USBInterface interfaceObj)
interfaceObj - Indicates a USBInterface object.true if the setting is successful; returns false otherwise.public boolean openByInt(String name, int fd)
name - Indicates the device name.fd - Indicates the file descriptor of the device connection.