usb.core
Class Device

java.lang.Object
  |
  +--usb.core.Device
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
DeviceImpl

public abstract class Device
extends java.lang.Object
implements java.io.Serializable

Provides access to a USB device.

To use a device, first make sure that you can use its current configuration. Then get the interfaces for that configuration and claim the ones you want to use. Then just use the endpoints from those interfaces. You might want to switch some interfaces to their alternate settings before you start using endpoints.

To provide behaviors specific to a device, or type of device, wrap one of these Device objects in a class that understands how to perform device-specific operations.


Except for a root hub, or when interrupted by disconnection, dev.getHub().getChild(dev.getHubPortNum() is equal to dev. However, it is good to avoid assuming that disconnects don't happen; they can be caused just by surge currents through hubs. Somewhat related: the best available view of hub parent/child relationships may not always match physical reality because of an inherent scheduling lag, and sometimes event reordering, that also affects USBListener.

See Also:
Bus.getDevice(int), USBListener, getHub(), getChild(int), Serialized Form

Field Summary
static int DEVICE_REMOTE_WAKEUP
          Device status bit used to enable and disable remote wakeup; this feature may be set and cleared.
static int DEVICE_SELFPOWERED
          Device status bit that reports the device is self powered.
 
Constructor Summary
protected Device()
          Used when deserializing.
protected Device(DeviceSPI spi, Bus bus, int address)
          Used by implementations of Host and Bus.
 
Method Summary
 void control(ControlMessage msg)
          Sends a control message to the device, optionally sending or receiving associated data.
 int getAddress()
          Returns address assigned to this device on its USB Bus.
 Bus getBus()
          Returns the bus with which the device is associated.
abstract  Device getChild(int port)
          Returns the device connected to this hub's specified port (origin one), or null.
abstract  Configuration getConfiguration()
          Returns the current device configuration's descriptor.
abstract  Configuration getConfiguration(int index)
          Returns the specified configuration descriptor.
abstract  DeviceDescriptor getDeviceDescriptor()
          Returns the device descriptor.
abstract  Device getHub()
          Returns the hub to which this device is connected, or null if this device is disconnected or is the root hub for its bus.
abstract  int getHubPortNum()
          Returns the number of the hub port to which this device is connected.
abstract  int getNumPorts()
          Returns the number of ports in this hub; or zero.
 java.lang.String getPortIdentifier()
          Returns port identifier associated with this device.
abstract  java.lang.String getSpeed()
          Returns the speed of the connection the device is using.
protected  DeviceSPI getSPI()
           
 java.lang.String getString(int id, int language)
          Returns the string index with the specified ID and language, or null if there is no such string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEVICE_SELFPOWERED

public static final int DEVICE_SELFPOWERED
Device status bit that reports the device is self powered. You can't set or clear this feature.

DEVICE_REMOTE_WAKEUP

public static final int DEVICE_REMOTE_WAKEUP
Device status bit used to enable and disable remote wakeup; this feature may be set and cleared.
Constructor Detail

Device

protected Device()
Used when deserializing.

Device

protected Device(DeviceSPI spi,
                 Bus bus,
                 int address)
Used by implementations of Host and Bus.
Method Detail

getSPI

protected DeviceSPI getSPI()

getBus

public final Bus getBus()
Returns the bus with which the device is associated.

getPortIdentifier

public final java.lang.String getPortIdentifier()
Returns port identifier associated with this device.

getAddress

public final int getAddress()
Returns address assigned to this device on its USB Bus. Addresses are established when the device is connected, get reused after devices disconnect, and don't correspond to anything that users can affect. In short, avoid using these.
See Also:
getPortIdentifier(), Bus.getDevice(int)

getHub

public abstract Device getHub()
Returns the hub to which this device is connected, or null if this device is disconnected or is the root hub for its bus.

getHubPortNum

public abstract int getHubPortNum()
Returns the number of the hub port to which this device is connected.

getSpeed

public abstract java.lang.String getSpeed()
Returns the speed of the connection the device is using. The return value is either "high", "full", or "low"; or else null. Null is used for root hubs, or indicates some error prevented determining the speed being used for the device's hub port.

getNumPorts

public abstract int getNumPorts()
Returns the number of ports in this hub; or zero. This should return the same value as Hub.getNumPorts().

getDeviceDescriptor

public abstract DeviceDescriptor getDeviceDescriptor()
Returns the device descriptor.

getConfiguration

public abstract Configuration getConfiguration()
                                        throws java.io.IOException
Returns the current device configuration's descriptor.

getChild

public abstract Device getChild(int port)
                         throws java.io.IOException
Returns the device connected to this hub's specified port (origin one), or null.

getConfiguration

public abstract Configuration getConfiguration(int index)
                                        throws java.io.IOException
Returns the specified configuration descriptor.

getString

public java.lang.String getString(int id,
                                  int language)
                           throws java.io.IOException
Returns the string index with the specified ID and language, or null if there is no such string. Zero as a language ID means to pick a default.

control

public void control(ControlMessage msg)
             throws java.io.IOException
Sends a control message to the device, optionally sending or receiving associated data. Control messages may be used whether or not you have claimed some interface.
Throws:
USBException - if exchanging a control message with an interface or endpoint some other driver has claimed


Associated source code is licenced under the LGPL.
See http://jusb.sourceforge.net
This documentation was derived from that source code on 24-Jul-2002.