usb.util
Class USBSocket

java.lang.Object
  |
  +--usb.util.USBSocket

public final class USBSocket
extends java.lang.Object

This provides basic access to USB interfaces which use only bulk I/O, and for devices which only offer such interfaces. Such access is found in many digital still cameras (including all current Kodak USB-aware cameras, and other cameras using the Digita OS), the Diamond Rio500 MP3 player, and other USB devices.

As with network sockets, be sure to close() these when you're no longer accessing the device. That permits other software to connect to the device.


Constructor Summary
USBSocket(Device dev)
          Initializes the socket using a bulk-only device.
USBSocket(Interface intf)
          Initializes the socket using a bulk-only interface on a device which may have additional interfaces.
 
Method Summary
 void close()
          Releases the interface, so that some other software driver can use it to access this device.
protected  void finalize()
          Finalization releases the interface, if it has not already been released by invoking close().
 Device getDevice()
          Returns the device to which this socket is connected, or null if the device has been closed or removed.
 java.io.InputStream getInputStream()
          Returns an input stream used to perform bulk reads from the interface, or null.
 java.io.OutputStream getOutputStream()
          Returns an output stream used to perform bulk writes to the interface, or null.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

USBSocket

public USBSocket(Device dev)
          throws java.io.IOException
Initializes the socket using a bulk-only device.
Throws:
java.io.IOException - if the interface is already claimed by another driver module; or if the configuration, interface, or endpoints can't be accessed; and for other reasons.
java.lang.IllegalArgumentException - if the interface doesn't have exactly two endpoints, for bulk input and bulk output.

USBSocket

public USBSocket(Interface intf)
          throws java.io.IOException
Initializes the socket using a bulk-only interface on a device which may have additional interfaces.
Throws:
java.io.IOException - if the interface is already claimed by another driver module, or if the endpoints can't be accessed.
java.lang.IllegalArgumentException - if the interface doesn't have exactly two endpoints, for bulk input and bulk output.
Method Detail

close

public void close()
           throws java.io.IOException
Releases the interface, so that some other software driver can use it to access this device. Both directions of the socket are closed down. The behavior seen by other threads trying to send or receive data is undefined.

finalize

protected void finalize()
                 throws java.io.IOException
Finalization releases the interface, if it has not already been released by invoking close().
Overrides:
finalize in class java.lang.Object

getInputStream

public java.io.InputStream getInputStream()
Returns an input stream used to perform bulk reads from the interface, or null.

getOutputStream

public java.io.OutputStream getOutputStream()
Returns an output stream used to perform bulk writes to the interface, or null.

getDevice

public Device getDevice()
Returns the device to which this socket is connected, or null if the device has been closed or removed.


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.