com.codeminders.hidapi
Class HIDDevice

java.lang.Object
  extended by com.codeminders.hidapi.HIDDevice

public class HIDDevice
extends java.lang.Object

Instance of this class represents an open HID device.

Author:
lord

Field Summary
protected  long peer
           
 
Constructor Summary
protected HIDDevice(long peer)
          Set peer to object.
 
Method Summary
 void close()
          Close open device.
 void disableBlocking()
          Disable blocking reads for this HIDDevice object.
 void enableBlocking()
          Enable blocking reads for this HIDDevice object.
 boolean equals(java.lang.Object obj)
          Method to compare HIDDevice object instances.
protected  void finalize()
          Destructor to destroy the HIDDevice object.
 int getFeatureReport(byte[] buf)
          Get a Feature Report from a HID device.
 java.lang.String getIndexedString(int string_index)
          Get a string from a HID device, based on its string index.
 java.lang.String getManufacturerString()
          Get The Manufacturer String from a HID device.
 java.lang.String getProductString()
          Get The Product String from a HID device.
 java.lang.String getSerialNumberString()
          Get The Serial Number String from a HID device.
 int hashCode()
          Returns a hash code for this HIDDevice object.
 int read(byte[] buf)
          Read an Input Report to a HID device.
 int readTimeout(byte[] buf, int milliseconds)
          Read an Input report from a HID device with timeout.
 int sendFeatureReport(byte[] data)
          Send a Feature Report to the HID device.
 int write(byte[] data)
          Write an Output Report to a HID device.
 
Methods inherited from class java.lang.Object
clone, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

peer

protected long peer
Constructor Detail

HIDDevice

protected HIDDevice(long peer)
Set peer to object.

Parameters:
peer - a peer value
Method Detail

finalize

protected void finalize()
                 throws java.lang.Throwable
Destructor to destroy the HIDDevice object. Calls the close() native method.

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

equals

public boolean equals(java.lang.Object obj)
Method to compare HIDDevice object instances.

Overrides:
equals in class java.lang.Object
Parameters:
obj - HIDDevice object reference
Returns:
true if the HIDDevice object represent the same value; false otherwise

hashCode

public int hashCode()
Returns a hash code for this HIDDevice object.

Overrides:
hashCode in class java.lang.Object
Returns:
a hash code value for this object

close

public void close()
           throws java.io.IOException
Close open device. Multiple calls allowed - id device was already closed no exception will be thrown.

Throws:
java.io.IOException - if error occured opening this device

write

public int write(byte[] data)
          throws java.io.IOException
Write an Output Report to a HID device.

Parameters:
data - the data to send, including the report number as the first byte
Returns:
the actual number of bytes written
Throws:
java.io.IOException - if write error occured

read

public int read(byte[] buf)
         throws java.io.IOException
Read an Input Report to a HID device.

Parameters:
buf - a buffer to put the read data into
Returns:
the actual number of bytes read
Throws:
java.io.IOException - if read error occured

readTimeout

public int readTimeout(byte[] buf,
                       int milliseconds)
Read an Input report from a HID device with timeout.

Parameters:
buf - a buffer to put the read data into.
milliseconds - a timeout in milliseconds or -1 for blocking wait.
Returns:
the number of bytes to read. For devices with multiple reports, make sure to read an extra byte for the report number.

enableBlocking

public void enableBlocking()
                    throws java.io.IOException
Enable blocking reads for this HIDDevice object.

Throws:
java.io.IOException

disableBlocking

public void disableBlocking()
                     throws java.io.IOException
Disable blocking reads for this HIDDevice object.

Throws:
java.io.IOException

sendFeatureReport

public int sendFeatureReport(byte[] data)
                      throws java.io.IOException
Send a Feature Report to the HID device.

Parameters:
data - The data to send, including the report number as the first byte
Returns:
the actual number of bytes written
Throws:
java.io.IOException

getFeatureReport

public int getFeatureReport(byte[] buf)
                     throws java.io.IOException
Get a Feature Report from a HID device.

Parameters:
buf - a buffer to put the read data into
Returns:
the actual number of bytes read and -1 on error
Throws:
java.io.IOException

getManufacturerString

public java.lang.String getManufacturerString()
                                       throws java.io.IOException
Get The Manufacturer String from a HID device.

Returns:
the string buffer to put the data into
Throws:
java.io.IOException

getProductString

public java.lang.String getProductString()
                                  throws java.io.IOException
Get The Product String from a HID device.

Returns:
the string buffer to put the data into
Throws:
java.io.IOException

getSerialNumberString

public java.lang.String getSerialNumberString()
                                       throws java.io.IOException
Get The Serial Number String from a HID device.

Returns:
the string buffer to put the data into
Throws:
java.io.IOException

getIndexedString

public java.lang.String getIndexedString(int string_index)
                                  throws java.io.IOException
Get a string from a HID device, based on its string index.

Parameters:
string_index - The index of the string to get.
Returns:
the string buffer to put the data into
Throws:
java.io.IOException