usb.windows
Class JUSB

java.lang.Object
  |
  +--usb.core.Device
        |
        +--usb.windows.DeviceImpl
              |
              +--usb.windows.JUSB
All Implemented Interfaces:
DeviceSPI, java.io.Serializable

public class JUSB
extends DeviceImpl
implements DeviceSPI

Provides access to the devices using and configured with the jUSB driver. This involves that a device must first be configured with the jUSB driver. How you can replace a driver from an USB device and attach the jUSB driver is completly explained in Appendix D in the JavaUSBAPIfor Windows documentation found on www.steelbrothers.ch/jusb/.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class usb.windows.DeviceImpl
configuration, descriptor, EXTERNAL_HUB, NO_DEVICE_CONNECTED, USB_DEVICE
 
Fields inherited from class usb.core.Device
DEVICE_REMOTE_WAKEUP, DEVICE_SELFPOWERED
 
Constructor Summary
JUSB(USB bus, DeviceImpl hub, java.lang.String devicePath, int address, java.lang.String driverKeyName, java.lang.String friendlyDevName, java.lang.String uniqueID, int portIndex)
          Creates a new instance of JUSB
 
Method Summary
 void claimInterface(int ifnum)
          Not implemented yet!
 int clearHalt(byte ep)
          Not implemented yet!
 Device getChild(int port)
          Not implemented yet!
 java.lang.String getClaimer(int ifnum)
          Not implemented yet!
 byte[] getConfigBuf(int n)
          Returns a buffer holding the entire set of configuration descriptors for the specified configuration.
 Configuration getConfiguration()
          Returns the default configuration from the device.
 Configuration getConfiguration(int index)
          Not implemented for all devices.
 java.lang.String getSpeed()
          Not implemented yet!
 byte[] readBulk(int ep, int length)
          Not implemented yet!
 byte[] readControl(byte type, byte request, short value, short index, short length)
          All USB device respond to request from the host on the device's Default ControlPipe.
 byte[] readIntr(int ep, int len)
          Reads a specified number of bytes from a INTERRUPT IN endpoint.
 void releaseInterface(int ifnum)
          Not implemented yet!
 void setInterface(int ifnum, int alt)
          Not implemented yet!
 void writeBulk(int ep, byte[] buf)
          Not implemented yet!
 void writeControl(byte type, byte request, short value, short index, byte[] buf)
          Not implemented yet!
 void writeIntr(int ep, byte[] buf)
          Not implemented yet!
 
Methods inherited from class usb.windows.DeviceImpl
closeHandle, getConfigurationDescriptor, getDeviceDescriptor, getDeviceDescriptor, getDeviceFriendlyName, getDevicePath, getDriverKeyName, getFriendlyDeviceName, getHub, getHubPortNum, getNumPorts, getUniqueDeviceID, openHandle, printByteArray
 
Methods inherited from class usb.core.Device
control, getAddress, getBus, getPortIdentifier, getSPI, getString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JUSB

public JUSB(USB bus,
            DeviceImpl hub,
            java.lang.String devicePath,
            int address,
            java.lang.String driverKeyName,
            java.lang.String friendlyDevName,
            java.lang.String uniqueID,
            int portIndex)
     throws java.io.IOException
Creates a new instance of JUSB

Method Detail

claimInterface

public void claimInterface(int ifnum)
                    throws java.io.IOException
Not implemented yet!

Suggestion for implementation:
Java Side
provide a native method which takes as argument the devicepath and the interface number.

jUSB DLL
Define a new IOCTL code such as IOCTL_JUSB_CLAIM_INTERFACE in the ioctls.h file. Call DeviceIoControl WinAPI function with the above IOCTL code and provide the interface number in the inptut buffer.

jUSB driver
In Control.c implement the IOCTL_JUSB_CLAIM_INTERFACE in that you update the device extension member "InterfaceClaimedInfo".

Specified by:
claimInterface in interface DeviceSPI
Parameters:
ifnum - Number from the descriptor, returned by Interface.getNumber().
java.io.IOException
See Also:
DeviceSPI.releaseInterface(int)

clearHalt

public int clearHalt(byte ep)
              throws java.io.IOException
Not implemented yet!

Suggestion for implementation:
Java Side
provide a native method which takes as argument the devicepath and the endpoint address.

jUSB DLL
Define a new IOCTL code such as IOCTL_JUSB_CLEAR_HALT in the ioctls.h file. Call DeviceIoControl WinAPI function with the above IOCTL code and provide the the endpoint address in the inptut buffer as input to the jUSB driver.

jUSB driver
In Control.c implement the IOCTL_JUSB_CLEAR_HALT.

Specified by:
clearHalt in interface DeviceSPI
Parameters:
ep - Endpoint address and direction, as returned by Endpoint.getEndpoint().
java.io.IOException

getChild

public Device getChild(int port)
                throws java.io.IOException
Not implemented yet!

Specified by:
getChild in interface DeviceSPI
Overrides:
getChild in class DeviceImpl
Parameters:
port - Number of the hub port of interest, from one to the Hub.getNumPorts().
Returns:
Device connected to that port, or null if there is no such device. Always returns null for devices that are not hubs.
java.io.IOException

getClaimer

public java.lang.String getClaimer(int ifnum)
                            throws java.io.IOException
Not implemented yet!

Suggestion for implementation:
Java Side
provide a native method which takes as argument the devicepath and the interface number.

jUSB DLL
Define a new IOCTL code such as IOCTL_JUSB_GET_CLAIMER in the ioctls.h file. Call DeviceIoControl WinAPI function with the above IOCTL code and provide the the interface number in the inptut buffer as input to the jUSB driver.

jUSB driver
In Control.c implement the IOCTL_JUSB_GET_CLAIMER in that you return the device extension member "ifname".

Specified by:
getClaimer in interface DeviceSPI
Parameters:
ifnum - Number from the descriptor, returned by Interface.getNumber().
Returns:
Driver name, or null to indicate the interface is not in use by any driver. Driver names are not standardized between host operating systems.
java.io.IOException

getConfigBuf

public byte[] getConfigBuf(int n)
                    throws java.io.IOException
Description copied from interface: DeviceSPI
Returns a buffer holding the entire set of configuration descriptors for the specified configuration. The format of those descriptors is described in the USB 2.0 specification.

Specified by:
getConfigBuf in interface DeviceSPI
Parameters:
n - Number of the configuration, from zero to the limit specified by DeviceDescriptor.getNumConfigurations()
java.io.IOException

readBulk

public byte[] readBulk(int ep,
                       int length)
                throws java.io.IOException
Not implemented yet!

Specified by:
readBulk in interface DeviceSPI
Parameters:
ep - Endpoint direction and address, as specified in an endpoint descriptor by Endpoint.getEndpoint().
length - How many bytes to read.
Returns:
The bytes actually read.
java.io.IOException

readControl

public byte[] readControl(byte type,
                          byte request,
                          short value,
                          short index,
                          short length)
                   throws java.io.IOException
All USB device respond to request from the host on the device's Default ControlPipe. These request are made using control transfer. The request and the request's parameters are sent to the device in the Setup packet. The host is responsible for establishing the setupPacket. Every Setup packet has eight bytes. USB device requests are discussed in section 9.3 of the USB 2.0 specification

Attention
Not all standard request are yet implemented in the jUSB driver

Specified by:
readControl in interface DeviceSPI
Parameters:
type - Masked together using three constants from ControlMessage: DIR_TO_HOST, a TYPE_*, and a RECIP_*.
request - bRequest field, either standard (from table 9-3 in the USB 2.0 specification) for TYPE_STANDARD, or else as specified in the class or vendor device type specification.
value - sixteen bit field associated with request
index - sixteen bit field associated with request
length - How much data should be read; may be zero to indicate that no READ phase follows the SETUP packet.
Returns:
The data read from the device. If this is shorter than the requested length, the caller must determine whether to treat that as an error. For example, it's typical to request a full size string descriptor, expecting to get back only the bytes that exist, rather than read a partial descriptor to learn the size, and then reading the whole thing.
java.io.IOException

readIntr

public byte[] readIntr(int ep,
                       int len)
                throws java.io.IOException
Description copied from interface: DeviceSPI
Reads a specified number of bytes from a INTERRUPT IN endpoint. This may be fewer bytes than were requested; the caller must decide whether that's an error in this case.

This blocks until an interrupt transfer completes. It's the caller's responsibility to ensure that the endpoint is polled often enough to meet Endpoint.getInterval() requirements after a transfer completes.

An endpoint's interface should be claimed before it is used for interrupt I/O.

Specified by:
readIntr in interface DeviceSPI
Parameters:
ep - Endpoint direction and address, as specified in an endpoint descriptor by Endpoint.getEndpoint().
Returns:
The bytes actually read.
java.io.IOException

releaseInterface

public void releaseInterface(int ifnum)
                      throws java.io.IOException
Not implemented yet!

Specified by:
releaseInterface in interface DeviceSPI
Parameters:
ifnum - Number from the descriptor, returned by Interface.getNumber().
java.io.IOException
See Also:
DeviceSPI.claimInterface(int)

setInterface

public void setInterface(int ifnum,
                         int alt)
                  throws java.io.IOException
Not implemented yet!

Specified by:
setInterface in interface DeviceSPI
Parameters:
ifnum - Number from the descriptor, returned by Interface.getNumber().
alt - Number from the descriptor, returned by Interface.getAlternateSetting().
java.io.IOException

writeBulk

public void writeBulk(int ep,
                      byte[] buf)
               throws java.io.IOException
Not implemented yet!

Specified by:
writeBulk in interface DeviceSPI
Parameters:
ep - Endpoint direction and address, as specified in an endpoint descriptor by Endpoint.getEndpoint().
buf - The bytes to write.
java.io.IOException

writeControl

public void writeControl(byte type,
                         byte request,
                         short value,
                         short index,
                         byte[] buf)
                  throws java.io.IOException
Not implemented yet!

Specified by:
writeControl in interface DeviceSPI
Parameters:
type - Masked together using three constants from ControlMessage: DIR_TO_DEVICE, a TYPE_*, and a RECIP_*.
request - bRequest field, either standard (from table 9-3 in the USB 2.0 specification) for TYPE_STANDARD, or else as specified in the class or vendor device type specification.
value - sixteen bit field associated with request
index - sixteen bit field associated with request
buf - The data to be written. Length may be zero to indicate that no WRITe phase follows the SETUP packet.
java.io.IOException

writeIntr

public void writeIntr(int ep,
                      byte[] buf)
               throws java.io.IOException
Not implemented yet!

Specified by:
writeIntr in interface DeviceSPI
Parameters:
ep - Endpoint direction and address, as specified in an endpoint descriptor by Endpoint.getEndpoint().
buf - The bytes to write.
java.io.IOException

getSpeed

public java.lang.String getSpeed()
Not implemented yet! The return value will always be null!

Overrides:
getSpeed in class DeviceImpl

getConfiguration

public Configuration getConfiguration(int index)
                               throws java.io.IOException
Description copied from class: DeviceImpl
Not implemented for all devices. So far it will return always null!

Overrides:
getConfiguration in class DeviceImpl
Returns:
Always null!
java.io.IOException

getConfiguration

public Configuration getConfiguration()
                               throws java.io.IOException
Description copied from class: DeviceImpl
Returns the default configuration from the device. The default configuration is is always configuration at index zero.

Overrides:
getConfiguration in class DeviceImpl
java.io.IOException