Top Description Fields Constructors Methods
javax.usb.util

public Class StandardRequest

extends Object
Class Inheritance
Imports
javax.usb.*

Utility to easily allow Standard Device Requests.

These methods are defined in the USB 1.1 specification section 9.4. The table 9.4 lists all Standard Requests.

Many of these methods have parameters whose type is short, but should never be passed more than a byte; e.g. all the interface number and endpoint address parameters have a type of short, but interface numbers and endpoint addresses are byte-sized.

Author
Dan Streetman

Field Summary

Modifier and TypeField and Description
protected static final byte
protected static final byte
protected static final byte
protected static final byte
protected static final byte
protected static final byte
protected static final byte
protected static final byte
protected static final byte
protected static final byte
protected static final byte
protected UsbDevice

Constructor Summary

AccessConstructor and Description
public
StandardRequest(UsbDevice
The UsbDevice to use.
usbDevice
)

Constructor.

Method Summary

Modifier and TypeMethod and Description
protected static void
checkRecipient(byte
The recipient.
recipient
)

Check the recipient.

public void
clearFeature(byte
The recipient.
recipient
,
short
The Feature Selector.
featureSelector
,
short
The target interface number or endpoint address.
target
)

Clear Feature.

public static void
clearFeature(UsbDevice
The UsbDevice.
usbDevice
,
byte
The recipient.
recipient
,
short
The Feature Selector.
featureSelector
,
short
The target interface number or endpoint address.
target
)

Clear Feature.

public byte

Returns:

The configuration number.
getConfiguration
()

Get Configuration.

public static byte

Returns:

The configuration number.
getConfiguration
(UsbDevice
The UsbDevice.
usbDevice
)

Get Configuration.

public int

Returns:

The actual length of transferred data.
getDescriptor
(byte
The Descriptor Type.
type
,
byte
The Descriptor Index.
index
,
short
The String Descriptor Language ID.
langid
,
byte[]
The data to fill with the Descriptor.
data
)

Get Descriptor.

public static int

Returns:

The actual length of transferred data.
getDescriptor
(UsbDevice
The UsbDevice.
usbDevice
,
byte
The Descriptor Type.
type
,
byte
The Descriptor Index.
index
,
short
The String Descriptor Language ID.
langid
,
byte[]
The data to fill with the Descriptor.
data
)

Get Descriptor.

public byte

Returns:

The active alternate setting for the specified interface.
getInterface
(short
The interface number.
interfaceNumber
)

Get Interface.

public static byte

Returns:

The active alternate setting for the specified interface.
getInterface
(UsbDevice
The UsbDevice.
usbDevice
,
short
The interface number.
interfaceNumber
)

Get Interface.

public short

Returns:

The status of the specified recipient.
getStatus
(byte
The recipient.
recipient
,
short
The target interface number or endpoint address.
target
)

Get Status.

public static short

Returns:

The status of the specified recipient.
getStatus
(UsbDevice
The UsbDevice.
usbDevice
,
byte
The recipient.
recipient
,
short
The target interface number or endpoint address.
target
)

Get Status.

public void
setAddress(short
The new device address.
deviceAddress
)

Set Address.

public static void
setAddress(UsbDevice
The UsbDevice.
usbDevice
,
short
The new device address.
deviceAddress
)

Set Address.

public void
setConfiguration(short
The new configuration value.
configurationValue
)

Set Configuration.

public static void
setConfiguration(UsbDevice
The UsbDevice.
usbDevice
,
short
The new configuration value.
configurationValue
)

Set Configuration.

public int

Returns:

The actual length of transferred data.
setDescriptor
(byte
The Descriptor Type.
type
,
byte
The Descriptor Index.
index
,
short
The String Descriptor Language ID.
langid
,
byte[]
The Descriptor.
data
)

Set Descriptor.

public static int

Returns:

The actual length of transferred data.
setDescriptor
(UsbDevice
The UsbDevice.
usbDevice
,
byte
The Descriptor Type.
type
,
byte
The Descriptor Index.
index
,
short
The String Descriptor Language ID.
langid
,
byte[]
The Descriptor.
data
)

Set Descriptor.

public void
setFeature(byte
The recipient.
recipient
,
short
The Feature Selector.
featureSelector
,
short
The target interface number or endpoint address.
target
)

Set Feature.

public static void
setFeature(UsbDevice
The UsbDevice.
usbDevice
,
byte
The recipient.
recipient
,
short
The Feature Selector.
featureSelector
,
short
The target interface number or endpoint address.
target
)

Set Feature.

public void
setInterface(short
The interface number.
interfaceNumber
,
short
The alternate setting number.
alternateSetting
)

Set Interface.

public static void
setInterface(UsbDevice
The UsbDevice.
usbDevice
,
short
The interface number.
interfaceNumber
,
short
The alternate setting number.
alternateSetting
)

Set Interface.

public short

Returns:

The frame number.
synchFrame
(short
The endpoint address.
endpointAddress
)

Synch Frame.

public static short

Returns:

The frame number.
synchFrame
(UsbDevice
The UsbDevice.
usbDevice
,
short
The endpoint address.
endpointAddress
)

Synch Frame.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

REQUESTTYPE_CLEAR_FEATUREback to summary
protected static final byte REQUESTTYPE_CLEAR_FEATURE
REQUESTTYPE_GET_CONFIGURATIONback to summary
protected static final byte REQUESTTYPE_GET_CONFIGURATION
REQUESTTYPE_GET_DESCRIPTORback to summary
protected static final byte REQUESTTYPE_GET_DESCRIPTOR
REQUESTTYPE_GET_INTERFACEback to summary
protected static final byte REQUESTTYPE_GET_INTERFACE
REQUESTTYPE_GET_STATUSback to summary
protected static final byte REQUESTTYPE_GET_STATUS
REQUESTTYPE_SET_ADDRESSback to summary
protected static final byte REQUESTTYPE_SET_ADDRESS
REQUESTTYPE_SET_CONFIGURATIONback to summary
protected static final byte REQUESTTYPE_SET_CONFIGURATION
REQUESTTYPE_SET_DESCRIPTORback to summary
protected static final byte REQUESTTYPE_SET_DESCRIPTOR
REQUESTTYPE_SET_FEATUREback to summary
protected static final byte REQUESTTYPE_SET_FEATURE
REQUESTTYPE_SET_INTERFACEback to summary
protected static final byte REQUESTTYPE_SET_INTERFACE
REQUESTTYPE_SYNCH_FRAMEback to summary
protected static final byte REQUESTTYPE_SYNCH_FRAME
usbDeviceback to summary
protected UsbDevice usbDevice

Constructor Detail

StandardRequestback to summary
public StandardRequest(UsbDevice usbDevice)

Constructor.

The specified UsbDevice will be used on the instance methods which do not include a UsbDevice parameter. The class methods which do include a UsbDevice parameter will use that UsbDevice.

Parameters
usbDevice:UsbDevice

The UsbDevice to use.

Method Detail

checkRecipientback to summary
protected static void checkRecipient(byte recipient) throws IllegalArgumentException

Check the recipient.

Valid recipients are device, interface, and endpoint.

Parameters
recipient:byte

The recipient.

Exceptions
IllegalArgumentException:
If the recipient is not valid.
clearFeatureback to summary
public void clearFeature(byte recipient, short featureSelector, short target) throws UsbException, IllegalArgumentException

Clear Feature.

This only calls the corresponding class method using the UsbDevice specified in the constructor.

Parameters
recipient:byte

The recipient.

featureSelector:short

The Feature Selector.

target:short

The target interface number or endpoint address.

Exceptions
UsbException:
If unsuccessful.
IllegalArgumentException:
If the recipient or target is invalid.
clearFeatureback to summary
public static void clearFeature(UsbDevice usbDevice, byte recipient, short featureSelector, short target) throws UsbException, IllegalArgumentException

Clear Feature.

Valid recipients are device, interface, and endpoint. If the recipient is device, the target must be 0. If the recipient is interface or endpoint, the target is the interface number or endpoint address, respectively.

Parameters
usbDevice:UsbDevice

The UsbDevice.

recipient:byte

The recipient.

featureSelector:short

The Feature Selector.

target:short

The target interface number or endpoint address.

Exceptions
UsbException:
If unsuccessful.
IllegalArgumentException:
If the recipient or target is invalid.
getConfigurationback to summary
public byte getConfiguration() throws UsbException

Get Configuration.

This only calls the corresponding class method using the UsbDevice specified in the constructor.

Returns:byte

The configuration number.

Exceptions
UsbException:
If unsuccessful.
getConfigurationback to summary
public static byte getConfiguration(UsbDevice usbDevice) throws UsbException

Get Configuration.

Parameters
usbDevice:UsbDevice

The UsbDevice.

Returns:byte

The configuration number.

Exceptions
UsbException:
If unsuccessful.
getDescriptorback to summary
public int getDescriptor(byte type, byte index, short langid, byte[] data) throws UsbException

Get Descriptor.

This only calls the corresponding class method using the UsbDevice specified in the constructor.

Parameters
type:byte

The Descriptor Type.

index:byte

The Descriptor Index.

langid:short

The String Descriptor Language ID.

data:byte[]

The data to fill with the Descriptor.

Returns:int

The actual length of transferred data.

Exceptions
UsbException:
If unsuccessful.
getDescriptorback to summary
public static int getDescriptor(UsbDevice usbDevice, byte type, byte index, short langid, byte[] data) throws UsbException

Get Descriptor.

The parameters correspond to the setup packet:

  • type is the wValue MSB
  • index is the wValue LSB
  • langid is the wIndex
  • data.length is the wLength

This method does not restrict the Descriptor type, but the device is only required to support those Descriptors defined in the USB 1.1 specification table 9.5, which includes device, configuration, and string descriptor types. Note that devices normally do not support requests for interface or endpoint descriptors; the configuration descriptor contains all its interface and endpoint descriptors.

If the type is string or configuration, the index is used to select the specific descriptor; for other descriptor types is should be 0 (this implementation does not enforce this).

If the type is string, the langid indicates what language to use. For other types it should be 0 (but this is not enforced).

The data is filled with the actual descriptor.

Parameters
usbDevice:UsbDevice

The UsbDevice.

type:byte

The Descriptor Type.

index:byte

The Descriptor Index.

langid:short

The String Descriptor Language ID.

data:byte[]

The data to fill with the Descriptor.

Returns:int

The actual length of transferred data.

Exceptions
UsbException:
If unsuccessful.
getInterfaceback to summary
public byte getInterface(short interfaceNumber) throws UsbException

Get Interface.

This only calls the corresponding class method using the UsbDevice specified in the constructor.

Parameters
interfaceNumber:short

The interface number.

Returns:byte

The active alternate setting for the specified interface.

Exceptions
UsbException:
If unsuccessful.
getInterfaceback to summary
public static byte getInterface(UsbDevice usbDevice, short interfaceNumber) throws UsbException

Get Interface.

Parameters
usbDevice:UsbDevice

The UsbDevice.

interfaceNumber:short

The interface number.

Returns:byte

The active alternate setting for the specified interface.

Exceptions
UsbException:
If unsuccessful.
getStatusback to summary
public short getStatus(byte recipient, short target) throws UsbException, IllegalArgumentException

Get Status.

This only calls the corresponding class method using the UsbDevice specified in the constructor.

Parameters
recipient:byte

The recipient.

target:short

The target interface number or endpoint address.

Returns:short

The status of the specified recipient.

Exceptions
UsbException:
If unsuccessful.
IllegalArgumentException:
If the recipient or target is invalid.
getStatusback to summary
public static short getStatus(UsbDevice usbDevice, byte recipient, short target) throws UsbException, IllegalArgumentException

Get Status.

Valid recipients are device, interface, and endpoint. If the recipient is device, the target must be 0. If the recipient is interface or endpoint, the target is the interface number or endpoint address, respectively.

Parameters
usbDevice:UsbDevice

The UsbDevice.

recipient:byte

The recipient.

target:short

The target interface number or endpoint address.

Returns:short

The status of the specified recipient.

Exceptions
UsbException:
If unsuccessful.
IllegalArgumentException:
If the recipient or target are invalid.
setAddressback to summary
public void setAddress(short deviceAddress) throws UsbException

Set Address.

This only calls the corresponding class method using the UsbDevice specified in the constructor.

Parameters
deviceAddress:short

The new device address.

Exceptions
UsbException:
If unsuccessful.
setAddressback to summary
public static void setAddress(UsbDevice usbDevice, short deviceAddress) throws UsbException

Set Address.

Since this is normally only used by the low-level Host Controller Driver, this quite likely will either fail or cause serious problems. This should not be used unless you know what you are doing and know that the Operating System's Host Controller Driver can handle this.

Parameters
usbDevice:UsbDevice

The UsbDevice.

deviceAddress:short

The new device address.

Exceptions
UsbException:
If unsuccessful.
setConfigurationback to summary
public void setConfiguration(short configurationValue) throws UsbException

Set Configuration.

This only calls the corresponding class method using the UsbDevice specified in the constructor.

Parameters
configurationValue:short

The new configuration value.

Exceptions
UsbException:
If unsuccessful.
setConfigurationback to summary
public static void setConfiguration(UsbDevice usbDevice, short configurationValue) throws UsbException

Set Configuration.

Parameters
usbDevice:UsbDevice

The UsbDevice.

configurationValue:short

The new configuration value.

Exceptions
UsbException:
If unsuccessful.
setDescriptorback to summary
public int setDescriptor(byte type, byte index, short langid, byte[] data) throws UsbException

Set Descriptor.

This only calls the corresponding class method using the UsbDevice specified in the constructor.

Parameters
type:byte

The Descriptor Type.

index:byte

The Descriptor Index.

langid:short

The String Descriptor Language ID.

data:byte[]

The Descriptor.

Returns:int

The actual length of transferred data.

Exceptions
UsbException:
If unsuccessful.
setDescriptorback to summary
public static int setDescriptor(UsbDevice usbDevice, byte type, byte index, short langid, byte[] data) throws UsbException

Set Descriptor.

The parameters correspond to the setup packet:

  • type is the wValue MSB
  • index is the wValue LSB
  • langid is the wIndex
  • data.length is the wLength

This method does not restrict the Descriptor type, but the device is only required to support those Descriptors defined in the USB 1.1 specification table 9.5, which includes device, configuration, and string descriptor types. Note that devices normally do not support requests for interface or endpoint descriptors; the configuration descriptor contains all its interface and endpoint descriptors.

If the type is string or configuration, the index is used to select the specific descriptor; for other descriptor types is should be 0 (this implementation does not enforce this).

If the type is string, the langid indicates what language to use. For other types it should be 0 (but this is not enforced).

The data should contain the actual Descriptor. The entire length is used, i.e. wLength is set to data.length.

Parameters
usbDevice:UsbDevice

The UsbDevice.

type:byte

The Descriptor Type.

index:byte

The Descriptor Index.

langid:short

The String Descriptor Language ID.

data:byte[]

The Descriptor.

Returns:int

The actual length of transferred data.

Exceptions
UsbException:
If unsuccessful.
setFeatureback to summary
public void setFeature(byte recipient, short featureSelector, short target) throws UsbException, IllegalArgumentException

Set Feature.

This only calls the corresponding class method using the UsbDevice specified in the constructor.

Parameters
recipient:byte

The recipient.

featureSelector:short

The Feature Selector.

target:short

The target interface number or endpoint address.

Exceptions
UsbException:
If unsuccessful.
IllegalArgumentException:
If the recipient or target is invalid.
setFeatureback to summary
public static void setFeature(UsbDevice usbDevice, byte recipient, short featureSelector, short target) throws UsbException, IllegalArgumentException

Set Feature.

Valid recipients are device, interface, and endpoint. If the recipient is device, the target is either 0 or the Test Selector. If the recipient is interface or endpoint, the target is the interface number or endpoint address, respectively.

Parameters
usbDevice:UsbDevice

The UsbDevice.

recipient:byte

The recipient.

featureSelector:short

The Feature Selector.

target:short

The target interface number or endpoint address.

Exceptions
UsbException:
If unsuccessful.
IllegalArgumentException:
If the recipient or target is invalid.
setInterfaceback to summary
public void setInterface(short interfaceNumber, short alternateSetting) throws UsbException

Set Interface.

This only calls the corresponding class method using the UsbDevice specified in the constructor.

Parameters
interfaceNumber:short

The interface number.

alternateSetting:short

The alternate setting number.

Exceptions
UsbException:
If unsuccessful.
setInterfaceback to summary
public static void setInterface(UsbDevice usbDevice, short interfaceNumber, short alternateSetting) throws UsbException

Set Interface.

Parameters
usbDevice:UsbDevice

The UsbDevice.

interfaceNumber:short

The interface number.

alternateSetting:short

The alternate setting number.

Exceptions
UsbException:
If unsuccessful.
synchFrameback to summary
public short synchFrame(short endpointAddress) throws UsbException

Synch Frame.

This only calls the corresponding class method using the UsbDevice specified in the constructor.

Parameters
endpointAddress:short

The endpoint address.

Returns:short

The frame number.

Exceptions
UsbException:
If unsuccessful.
synchFrameback to summary
public static short synchFrame(UsbDevice usbDevice, short endpointAddress) throws UsbException

Synch Frame.

Parameters
usbDevice:UsbDevice

The UsbDevice.

endpointAddress:short

The endpoint address.

Returns:short

The frame number.

Exceptions
UsbException:
If unsuccessful.