In order to make control requests and transfer data, the device must be opened and an interface must be claimed. In the open state, this current process has exclusive access to the device.
Information about the device can be queried in both the open and the closed state.
-
Method Summary
Modifier and TypeMethodDescriptionvoidclaimInterface(int interfaceNumber) Claims the specified interface for exclusive use.intUSB device class code (bDeviceClassfrom device descriptor).voidclose()Closes the device.byte[]controlTransferIn(USBControlTransfer setup, int length) Requests data from the control endpoint.voidcontrolTransferOut(USBControlTransfer setup, byte[] data) Executes a control transfer request and optionally sends data.Gets the interfaces of this device.booleanisOpen()Indicates if the device is open.Manufacturer namevoidopen()Opens the device for communication.product()Product name.intUSB product ID.intUSB device protocol (bDeviceProtocolfrom device descriptor).voidreleaseInterface(int interfaceNumber) Releases the specified interface from exclusive use.Serial numberintUSB device subclass code (bDeviceSubClassfrom device descriptor).byte[]transferIn(int endpointNumber, int maxLength) Receives data to this device.voidtransferOut(int endpointNumber, byte[] data) Sends data to this device.intvendorId()USB vendor ID.
-
Method Details
-
productId
int productId()USB product ID.- Returns:
- product ID
-
vendorId
int vendorId()USB vendor ID.- Returns:
- vendor ID
-
product
String product()Product name.- Returns:
- product name or
nullif not provided by the device
-
manufacturer
String manufacturer()Manufacturer name- Returns:
- manufacturer name or
nullif not provided by the device
-
serialNumber
String serialNumber()Serial numberEven though this is supposed to be a human-readable string, some devices are known to provide binary data.
- Returns:
- serial number or
nullif not provided by the device
-
classCode
int classCode()USB device class code (bDeviceClassfrom device descriptor).- Returns:
- class code
-
subclassCode
int subclassCode()USB device subclass code (bDeviceSubClassfrom device descriptor).- Returns:
- subclass code
-
protocolCode
int protocolCode()USB device protocol (bDeviceProtocolfrom device descriptor).- Returns:
- protocol code
-
open
void open()Opens the device for communication. -
isOpen
boolean isOpen()Indicates if the device is open.- Returns:
trueif the device is open,falseif it is closed.
-
close
void close()Closes the device. -
interfaces
List<USBInterface> interfaces()Gets the interfaces of this device.- Returns:
- a list of USB interfaces
-
claimInterface
void claimInterface(int interfaceNumber) Claims the specified interface for exclusive use.- Parameters:
interfaceNumber- the interface number
-
releaseInterface
void releaseInterface(int interfaceNumber) Releases the specified interface from exclusive use.- Parameters:
interfaceNumber- the interface number
-
controlTransferIn
Requests data from the control endpoint.This method blocks until the device has responded or an error has occurred.
The control transfer request is sent to endpoint 0. The transfer is expected to have a Data In stage.
- Parameters:
setup- control transfer setup parameterslength- maximum length of expected data- Returns:
- received data.
-
controlTransferOut
Executes a control transfer request and optionally sends data.This method blocks until the device has acknowledge the request or an error has occurred.
The control transfer request is sent to endpoint 0. The transfer is expected to either have no data stage or a Data Out stage.
- Parameters:
setup- control transfer setup parametersdata- data to send, ornullif the transfer has no data stage.
-
transferOut
void transferOut(int endpointNumber, byte[] data) Sends data to this device.This method blocks until the data has been sent or an error has occurred.
This method is suitable for bulk and interrupt endpoints.
- Parameters:
endpointNumber- endpoint number (in the range between 1 and 127)data- data to send
-
transferIn
byte[] transferIn(int endpointNumber, int maxLength) Receives data to this device.This method blocks until at least a packet has been received or an error has occurred. The minimum value for
maxLengthis the maximum size of packets sent on the endpoint.This method is suitable for bulk and interrupt endpoints.
- Parameters:
endpointNumber- endpoint number (in the range between 1 and 127, i.e. without the direction bit)maxLength- the maximum data length to receive (in number of bytes)- Returns:
- received data
-