diff --git a/java/.classpath b/java/.classpath
index 4eb8e08..91624f7 100644
--- a/java/.classpath
+++ b/java/.classpath
@@ -4,5 +4,6 @@
+
diff --git a/java/.project b/java/.project
index 9aa9f0b..d404604 100644
--- a/java/.project
+++ b/java/.project
@@ -20,11 +20,17 @@
+
+ net.sf.eclipsensis.installoptions.InstallOptionsBuilder
+
+
+
org.eclipse.jem.workbench.JavaEMFNature
org.eclipse.jdt.core.javanature
org.eclipse.jem.beaninfo.BeanInfoNature
org.eclipse.pde.PluginNature
+ net.sf.eclipsensis.installoptions.InstallOptionsNature
diff --git a/java/META-INF/MANIFEST.MF b/java/META-INF/MANIFEST.MF
index 5718e20..67ec8ca 100644
--- a/java/META-INF/MANIFEST.MF
+++ b/java/META-INF/MANIFEST.MF
@@ -1,9 +1,13 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
-Bundle-Name: Java libusb wrapper
-Bundle-SymbolicName: ch.ntb.usb
+Bundle-Name: Java libusb-1.0 wrapper
+Bundle-SymbolicName: ch.ntb.inf.libusbJava
Bundle-Version: 1.0.2
Bundle-Vendor: libusbjava.sourceforge.net
Require-Bundle: org.junit4
-Export-Package: ch.ntb.inf.libusbJava
+Export-Package: ch.ntb.inf.libusbJava,
+ ch.ntb.inf.libusbJava.logger,
+ ch.ntb.inf.libusbJava.testApp,
+ ch.ntb.inf.libusbJava.usbView
Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Import-Package: ch.ntb.inf.libusbJava
diff --git a/java/UsbView.launch b/java/UsbView.launch
new file mode 100644
index 0000000..e067e1e
--- /dev/null
+++ b/java/UsbView.launch
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/java/build.properties b/java/build.properties
index c7069a0..4790385 100644
--- a/java/build.properties
+++ b/java/build.properties
@@ -1,4 +1 @@
-source.. = src/,\
- test/
-bin.includes = META-INF/,\
- .
+# MTJ Build Properties
diff --git a/java/build.xml b/java/build.xml
index b154039..00f17ad 100644
--- a/java/build.xml
+++ b/java/build.xml
@@ -14,7 +14,7 @@
-
+
diff --git a/java/project.properties b/java/project.properties
index bd48a3e..6c301cf 100644
--- a/java/project.properties
+++ b/java/project.properties
@@ -1,4 +1,4 @@
-#Thu Aug 24 14:28:28 CEST 2006
+#Tue Mar 30 10:58:35 CEST 2010
project.name=ch.ntb.inf.libusbJava
project.vendor=inf.ntb.ch
project.dir.src=src
diff --git a/java/src/ch/ntb/inf/libusbJava/Device.java b/java/src/ch/ntb/inf/libusbJava/Device.java
index a345a78..8979a14 100644
--- a/java/src/ch/ntb/inf/libusbJava/Device.java
+++ b/java/src/ch/ntb/inf/libusbJava/Device.java
@@ -223,9 +223,9 @@ public class Device {
if (dev != null) {
long res = LibusbJava.usb_open(dev);
- if (res == 0) {
+ if (res <= 0) {
throw new USBException("LibusbJava.usb_open: "
- + LibusbJava.usb_strerror());
+ + LibusbJava.usb_strerror() + " (" + res + ")");
}
usbDevHandle = res;
}
@@ -743,14 +743,20 @@ public class Device {
}
/**
- * Check if the device is open.
- * This checks only for a valid device handle. It doesn't check if the
- * device is still attached or working.
+ * Check if the device is open, attached and work.
*
- * @return true if the device is open
+ * @return true if the device is open and work.
*/
public boolean isOpen() {
- return usbDevHandle != 0;
+ if(usbDevHandle != 0){
+ try {
+ updateDescriptors();
+ } catch (USBException e) {
+ return false;
+ }
+ return dev != null;
+ }
+ return false;
}
/**
diff --git a/java/src/ch/ntb/inf/libusbJava/LibusbJava.java b/java/src/ch/ntb/inf/libusbJava/LibusbJava.java
index f96dac3..cea1f16 100644
--- a/java/src/ch/ntb/inf/libusbJava/LibusbJava.java
+++ b/java/src/ch/ntb/inf/libusbJava/LibusbJava.java
@@ -4,32 +4,22 @@
*
* http://libusbjava.sourceforge.net
* This library is covered by the LGPL, read LGPL.txt for details.
+ *
+ * Changes:
+ * 18.10.2010 NTB / Roger Millischer change from native interface to compatibility layer
+ *
*/
package ch.ntb.inf.libusbJava;
/**
- * This class represents the Java Native Interface to the shared library which
- * is (with some exceptions) a one-to-one representation of the libusb API.
- *
- *
Project Description
- * Java libusb is a Java wrapper for the libusb and libusb-win32 USB library.
- *
- * libusb aim is to create a
- * library for use by user level applications to access USB devices regardless
- * of OS.
- * Libusb-win32 is a port of
- * the USB library libusb to the
- * Windows operating systems. The library allows user space applications to
- * access any USB device on Windows in a generic way without writing any line of
- * kernel driver code.
- *
- * The API description of this class has been copied from the libusb documentation
- * and adapted where neccessary.
+ * This class is used as compatibility layer for libusb 0.1 projects. For new
+ * projects use {@link LibusbJava1}
*
*/
public class LibusbJava {
+ private static Usb_Bus busses = null;
+ private static long defaultCTX = 0;
/**
* System error codes.
* This list is not complete! For more error codes see the file 'errorno.h'
@@ -49,15 +39,29 @@ public class LibusbJava {
* @param level
* 0 to 255
*/
- public static native void usb_set_debug(int level);
+ public static void usb_set_debug(int level) {
+ LibusbJava1.libusb_set_debug(0, level);
+ }
// Core
/**
* Just like the name implies, usb_init sets up some internal
- * structures. usb_init must be called before any other
- * libusb functions.
+ * structures. usb_init must be called before any other libusb
+ * functions.
*/
- public static native void usb_init();
+ public static void usb_init() {
+ if (defaultCTX > 0) {
+ return;
+ }
+ defaultCTX = LibusbJava1.libusb_init();
+ LibusbJava1.libusb_set_debug(0, 0);
+ if (defaultCTX < 0) {
+ System.out.println("LibusbJava-1.0 init failed with errorcode: "
+ + defaultCTX);
+ return;
+ }
+
+ }
/**
* usb_find_busses will find all of the busses on the system.
@@ -65,7 +69,107 @@ public class LibusbJava {
* @return the number of changes since previous call to this function (total
* of new busses and busses removed).
*/
- public static native int usb_find_busses();
+ public static int usb_find_busses() {
+ int changes = 0;
+ long tmpBusNumber;
+ Usb_Bus nbusses = null;
+ Usb_Bus bus = nbusses, tmp;
+ boolean found = false;
+ Usb_Device devices = null;
+ devices = LibusbJava1.libusb_get_device_list(0);
+
+ // no busses
+ if (devices.getDevnum() == -1) {
+ while (busses != null) {
+ changes++;
+ busses = busses.getNext();
+ }
+ return changes;
+ }
+ // find busses
+ while (devices != null) {
+ tmpBusNumber = (long) LibusbJava1.libusb_get_bus_number(devices);
+ while (bus != null) {
+ if (bus.getLocation() == tmpBusNumber) {
+ found = true;
+ break;
+ }
+ bus = bus.getNext();
+ }
+ if (found) {
+ devices = devices.getNext();
+ found = false;
+ continue;
+ }
+ if (nbusses == null) {
+ nbusses = new Usb_Bus(Long.toString(tmpBusNumber), tmpBusNumber);
+ } else {
+ tmp = new Usb_Bus(Long.toString(tmpBusNumber), tmpBusNumber);
+ bus = nbusses;
+ // append
+ while (bus.getNext() != null) {
+ bus = bus.getNext();
+ }
+ tmp.setPrev(bus);
+ bus.setNext(tmp);
+ }
+ bus = nbusses;
+ devices = devices.getNext();
+ }
+ // compare to existing bus-list
+ bus = busses;
+ tmp = nbusses;
+ found = false;
+ while (bus != null) {
+ tmpBusNumber = bus.getLocation();
+ while (tmp != null) {
+ if (tmpBusNumber == tmp.getLocation()) {
+ found = true;
+ // remove from nbusses list
+ if (tmp.getPrev() != null) {
+ tmp.getPrev().setNext(tmp.getNext());
+ } else {
+ nbusses = tmp.getNext();
+ }
+ if (tmp.getNext() != null) {
+ tmp.getNext().setPrev(tmp.getPrev());
+ }
+ break;
+ }
+ tmp = tmp.getNext();
+ }
+ if (!found) {
+ // remove from busses an increment changes
+ if (bus.getPrev() != null) {
+ bus.getPrev().setNext(bus.getNext());
+ } else {
+ busses = bus.getNext();
+ }
+ if (bus.getNext() != null) {
+ bus.getNext().setPrev(bus.getPrev());
+ }
+ changes++;
+ }
+ bus = bus.getNext();
+ tmp = nbusses;
+ found = false;
+ }
+ // add new busses
+ bus = busses;
+ while (tmp != null) {
+ tmp = tmp.getNext();
+ changes++;
+ }
+ if (busses != null) {
+ while (bus.getNext() != null) {
+ bus = bus.getNext();
+ }
+ bus.setNext(nbusses);
+ } else {
+ busses = nbusses;
+ }
+ return changes;
+ }
/**
* usb_find_devices will find all of the devices on each bus.
@@ -74,7 +178,85 @@ public class LibusbJava {
* @return the number of changes since the previous call to this function
* (total of new device and devices removed).
*/
- public static native int usb_find_devices();
+ public static int usb_find_devices() {
+ int changes = 0;
+ byte tmpDevnum;
+ long tmpBusNumber;
+ Usb_Bus bus = busses;
+ boolean found = false;
+ Usb_Device devices, dev, ndev;
+
+ devices = LibusbJava1.libusb_get_device_list(0);
+ // Compare to existing bus-structure and remove removed devices
+ while (bus != null) {
+ dev = bus.getDevices();
+ while (dev != null) {
+ tmpDevnum = dev.getDevnum();
+ ndev = devices;
+ while (ndev != null) {
+ // if dev already exist remove from ndev list
+ if (tmpDevnum == ndev.getDevnum()) {
+ found = true;
+ if (ndev.getPrev() != null) {
+ ndev.getPrev().setNext(ndev.getNext());
+ } else {
+ devices = ndev.getNext();
+ }
+ if (ndev.getNext() != null) {
+ ndev.getNext().setPrev(ndev.getPrev());
+ }
+ break;
+ }
+ ndev = ndev.getNext();
+ }
+ if (!found) {
+ // remove device from bus an increment changes
+ if (dev.getPrev() != null) {
+ dev.getPrev().setNext(dev.getNext());
+ } else {
+ bus.setDevices(dev.getNext());
+ }
+ if (dev.getNext() != null) {
+ dev.getNext().setPrev(dev.getPrev());
+ }
+ changes++;
+ } else {
+ found = false;
+ }
+ dev = dev.getNext();
+ }
+ bus = bus.getNext();
+ }
+ // Add new Devices
+ bus = busses;
+ while (devices != null) {
+ ndev = devices.getNext();
+ // find correct bus
+ tmpBusNumber = (long) LibusbJava1.libusb_get_bus_number(devices);
+ while (bus != null) {
+ if (bus.getLocation() == tmpBusNumber) {
+ break;
+ }
+ bus = bus.getNext();
+ }
+ // insert device
+ if (bus != null) {
+ if (bus.getDevices() == null) {
+ devices.setNext(null);
+ } else {
+ devices.setNext(bus.getDevices());
+ devices.getNext().setPrev(devices);
+ }
+ devices.setPrev(null);
+ bus.setDevices(devices);
+ devices.setBus(bus);
+ changes++;
+ }
+ devices = ndev;
+ bus = busses;
+ }
+ return changes;
+ }
/**
* usb_get_busses returns a tree of descriptor objects.
@@ -87,7 +269,9 @@ public class LibusbJava {
* @return the structure of all busses and devices. Note: The
* java objects are copies of the C structs.
*/
- public static native Usb_Bus usb_get_busses();
+ public static Usb_Bus usb_get_busses() {
+ return busses;
+ }
// Device Operations
/**
@@ -100,17 +284,22 @@ public class LibusbJava {
* @return a handle used in future communication with the device. 0 if an
* error has occurred.
*/
- public static native long usb_open(Usb_Device dev);
+ public static long usb_open(Usb_Device dev) {
+// return LibusbJava1.libusb_open_device_with_vid_pid(defaultCTX, dev.getDescriptor().getIdVendor(), dev.getDescriptor().getIdProduct());
+ return LibusbJava1.libusb_open(dev);
+ }
/**
- * usb_close closes a device opened with
- * usb_open.
+ * usb_close closes a device opened with usb_open.
*
* @param dev_handle
* The handle to the device.
- * @return 0 on success or < 0 on error.
+ * @return 0
*/
- public static native int usb_close(long dev_handle);
+ public static int usb_close(long dev_handle) {
+ LibusbJava1.libusb_close(dev_handle);
+ return 0;
+ }
/**
* Sets the active configuration of a device
@@ -122,8 +311,9 @@ public class LibusbJava {
* bConfigurationValue.
* @return 0 on success or < 0 on error.
*/
- public static native int usb_set_configuration(long dev_handle,
- int configuration);
+ public static int usb_set_configuration(long dev_handle, int configuration) {
+ return LibusbJava1.libusb_set_configuration(dev_handle, configuration);
+ }
/**
* Sets the active alternate setting of the current interface
@@ -135,7 +325,26 @@ public class LibusbJava {
* bAlternateSetting.
* @return 0 on success or < 0 on error.
*/
- public static native int usb_set_altinterface(long dev_handle, int alternate);
+ public static int usb_set_altinterface(long dev_handle, int alternate) {
+ Usb_Device dev = LibusbJava1.libusb_get_device(dev_handle);
+ int nofInterfaces = LibusbJava1
+ .libusb_get_active_config_descriptor(dev).getBNumInterfaces();
+ int interface_number, success = -1;
+ for (interface_number = 0; interface_number < nofInterfaces; interface_number++) {
+ success = LibusbJava1.libusb_release_interface(dev_handle,
+ interface_number);
+ if (success >= 0) {
+ success = LibusbJava1.libusb_claim_interface(dev_handle,
+ interface_number);
+ if (success < 0) {
+ return success;
+ }
+ break;
+ }
+ }
+ return LibusbJava1.libusb_set_interface_alt_setting(dev_handle,
+ interface_number, alternate);
+ }
/**
* Clears any halt status on an endpoint.
@@ -146,27 +355,37 @@ public class LibusbJava {
* The value specified in the descriptor field bEndpointAddress.
* @return 0 on success or < 0 on error.
*/
- public static native int usb_clear_halt(long dev_handle, int ep);
+ public static int usb_clear_halt(long dev_handle, int ep) {
+
+ return LibusbJava1.libusb_clear_halt(dev_handle, (short) ep);
+ }
/**
* Resets a device by sending a RESET down the port it is connected to.
*
- * Causes re-enumeration: After calling usb_reset,
- * the device will need to re-enumerate and thusly, requires you to find the
- * new device and open a new handle. The handle used to call
+ * Causes re-enumeration: After calling usb_reset, the
+ * device will need to re-enumerate and thusly, requires you to find the new
+ * device and open a new handle. The handle used to call
* usb_reset will no longer work.
*
* @param dev_handle
* The handle to the device.
* @return 0 on success or < 0 on error.
*/
- public static native int usb_reset(long dev_handle);
+ public static int usb_reset(long dev_handle) {
+ LibusbJava1.libusb_claim_interface(dev_handle, 0);
+ int res = LibusbJava1.libusb_reset_device(dev_handle);
+ LibusbJava1.libusb_release_interface(dev_handle, 0);
+ LibusbJava1.libusb_close(dev_handle);
+ return res;
+
+ }
/**
* Claim an interface of a device.
*
- * Must be called!: usb_claim_interface must be
- * called before you perform any operations related to this interface (like
+ * Must be called!: usb_claim_interface must be called
+ * before you perform any operations related to this interface (like
* usb_set_altinterface, usb_bulk_write, etc).
*
* @param dev_handle
@@ -176,7 +395,9 @@ public class LibusbJava {
* bInterfaceNumber.
* @return 0 on success or < 0 on error.
*/
- public static native int usb_claim_interface(long dev_handle, int interface_);
+ public static int usb_claim_interface(long dev_handle, int interface_) {
+ return LibusbJava1.libusb_claim_interface(dev_handle, interface_);
+ }
/**
* Releases a previously claimed interface
@@ -188,8 +409,9 @@ public class LibusbJava {
* bInterfaceNumber.
* @return 0 on success or < 0 on error.
*/
- public static native int usb_release_interface(long dev_handle,
- int interface_);
+ public static int usb_release_interface(long dev_handle, int interface_) {
+ return LibusbJava1.libusb_release_interface(dev_handle, interface_);
+ }
// Control Transfers
/**
@@ -207,9 +429,12 @@ public class LibusbJava {
* @param timeout
* @return the number of bytes written/read or < 0 on error.
*/
- public static native int usb_control_msg(long dev_handle, int requesttype,
+ public static int usb_control_msg(long dev_handle, int requesttype,
int request, int value, int index, byte[] bytes, int size,
- int timeout);
+ int timeout) {
+ return LibusbJava1.libusb_control_transfer(dev_handle, requesttype,
+ request, value, index, bytes, size, timeout);
+ }
/**
* Retrieves the string descriptor specified by index and langid from a
@@ -221,8 +446,10 @@ public class LibusbJava {
* @param langid
* @return the descriptor String or null
*/
- public static native String usb_get_string(long dev_handle, int index,
- int langid);
+ public static String usb_get_string(long dev_handle, int index, int langid) {
+
+ return LibusbJava1.libusb_get_string_descriptor(dev_handle, (short) index, langid, 255);
+ }
/**
* usb_get_string_simple is a wrapper around
@@ -234,7 +461,9 @@ public class LibusbJava {
* @param index
* @return the descriptor String or null
*/
- public static native String usb_get_string_simple(long dev_handle, int index);
+ public static String usb_get_string_simple(long dev_handle, int index) {
+ return LibusbJava1.libusb_get_string_descriptor_ascii(dev_handle,(short) index, 255);
+ }
/**
* Retrieves a descriptor from the device identified by the type and index
@@ -252,8 +481,10 @@ public class LibusbJava {
* resulting String)
* @return the descriptor String or null
*/
- public static native String usb_get_descriptor(long dev_handle, byte type,
- byte index, int size);
+ public static byte[] usb_get_descriptor(long dev_handle, byte type,
+ byte index, int size) {
+ return LibusbJava1.libusb_get_descriptor(dev_handle, type, index, size);
+ }
/**
* Retrieves a descriptor from the device identified by the type and index
@@ -269,8 +500,24 @@ public class LibusbJava {
* resulting String)
* @return the descriptor String or null
*/
- public static native String usb_get_descriptor_by_endpoint(long dev_handle,
- int ep, byte type, byte index, int size);
+ public static String usb_get_descriptor_by_endpoint(long dev_handle,
+ int ep, byte type, byte index, int size) {
+
+ // We just send a control message directly;
+ byte data[] = new byte[size];
+ char string[] = new char[size];
+ int transfered;
+ transfered = LibusbJava1.libusb_control_transfer(dev_handle,
+ 0x80 | (ep & 0xFF), 0x07, (type << 8) | index, 0, data, size,
+ 1000);
+ if (transfered > 0) {
+ for (int i = 0; i < transfered; i++) {
+ string[i] = (char) data[i];
+ }
+ return String.valueOf(string);
+ }
+ return null;
+ }
// Bulk Transfers
/**
@@ -284,8 +531,11 @@ public class LibusbJava {
* @param timeout
* @return the number of bytes written on success or < 0 on error.
*/
- public static native int usb_bulk_write(long dev_handle, int ep,
- byte[] bytes, int size, int timeout);
+ public static int usb_bulk_write(long dev_handle, int ep, byte[] bytes,
+ int size, int timeout) {
+ return LibusbJava1.libusb_bulk_transfer(dev_handle, (byte) ep, bytes,
+ size, timeout);
+ }
/**
* Performs a bulk read request to the endpoint specified by ep.
@@ -298,8 +548,11 @@ public class LibusbJava {
* @param timeout
* @return the number of bytes read on success or < 0 on error.
*/
- public static native int usb_bulk_read(long dev_handle, int ep,
- byte[] bytes, int size, int timeout);
+ public static int usb_bulk_read(long dev_handle, int ep, byte[] bytes,
+ int size, int timeout) {
+ return LibusbJava1.libusb_bulk_transfer(dev_handle, (byte) ep, bytes,
+ size, timeout);
+ }
// Interrupt Transfers
/**
@@ -313,8 +566,11 @@ public class LibusbJava {
* @param timeout
* @return the number of bytes written on success or < 0 on error.
*/
- public static native int usb_interrupt_write(long dev_handle, int ep,
- byte[] bytes, int size, int timeout);
+ public static int usb_interrupt_write(long dev_handle, int ep,
+ byte[] bytes, int size, int timeout) {
+ return LibusbJava1.libusb_interrupt_transfer(dev_handle, (byte) ep,
+ bytes, size, timeout);
+ }
/**
* Performs a interrupt read request to the endpoint specified by ep.
@@ -327,52 +583,19 @@ public class LibusbJava {
* @param timeout
* @return the number of bytes read on success or < 0 on error.
*/
- public static native int usb_interrupt_read(long dev_handle, int ep,
- byte[] bytes, int size, int timeout);
+ public static int usb_interrupt_read(long dev_handle, int ep, byte[] bytes,
+ int size, int timeout) {
+ return LibusbJava1.libusb_interrupt_transfer(dev_handle, (byte) ep,
+ bytes, size, timeout);
+ }
/**
* Returns the error string after an error occured.
*
* @return the last error sring.
*/
- public static native String usb_strerror();
-
- /** **************************************************************** */
-
- /**
- * Maps the Java error code to the system error code.
- *
- * Note that not all error codes are be mapped by this method. For more
- * error codes see the file 'errno.h' on your system.
- *
- * 1: EBADF: Bad file descriptor.
- * 2: ENXIO: No such device or address.
- * 3: EBUSY: Device or resource busy.
- * 4: EINVAL: Invalid argument.
- * 5: ETIMEDOUT: Connection timed out.
- * 6: EIO: I/O error.
- * 7: ENOMEM: Not enough memory.
- *
- *
- * @return the system error code or 100000 if no mapping has been found.
- */
- private static native int usb_error_no(int value);
-
- static {
- String os = System.getProperty("os.name");
- if (os.contains("Windows")) {
- System.loadLibrary("LibusbJava");
- } else {
- System.loadLibrary("usbJava");
- }
- // define the error codes
- ERROR_SUCCESS = 0;
- ERROR_BAD_FILE_DESCRIPTOR = -usb_error_no(1);
- ERROR_NO_SUCH_DEVICE_OR_ADDRESS = -usb_error_no(2);
- ERROR_BUSY = -usb_error_no(3);
- ERROR_INVALID_PARAMETER = -usb_error_no(4);
- ERROR_TIMEDOUT = -usb_error_no(5);
- ERROR_IO_ERROR = -usb_error_no(6);
- ERROR_NOT_ENOUGH_MEMORY = -usb_error_no(7);
+ public static String usb_strerror() {
+ return LibusbJava1.libusb_strerror();
}
+
}
\ No newline at end of file
diff --git a/java/src/ch/ntb/inf/libusbJava/LibusbJava1.java b/java/src/ch/ntb/inf/libusbJava/LibusbJava1.java
new file mode 100644
index 0000000..b463f93
--- /dev/null
+++ b/java/src/ch/ntb/inf/libusbJava/LibusbJava1.java
@@ -0,0 +1,1339 @@
+/**
+ * Java libusb1.0 wrapper
+ * Roger Millischer
+ *
+ * This library is covered by the LGPL, read LGPL.txt for details.
+ */
+package ch.ntb.inf.libusbJava;
+
+/**
+ * This class represents the Java Native Interface to the shared library which
+ * is (with some exceptions) a one-to-one representation of the libusb1.0 API.
+ *
+ * Project Description
Java libusb1.0 is a Java wrapper for the
+ * libusb1.0 USB library.
+ *
+ * libusb aim is to create a library for
+ * use by user level applications to access USB devices regardless of OS.
+ * Libusb-Windows
+ * backend aim of this project is to bring a Windows backend to the mainline
+ * libusb 1.0 branch, so that libusb 1.0 can easily be used on Windows
+ * platforms. The library allows user space applications to access any USB
+ * device on Windows in a generic way without writing any line of kernel driver
+ * code.
+ *
+ * The API description of this class has been copied from the libusb-1.0 API
+ * Reference and adapted where neccessary.
+ *
+ */
+public class LibusbJava1 {
+
+ /**
+ * System error codes.
+ * This list is not complete! For more error codes see the file 'errorno.h'
+ * on your system.
+ */
+ public static final int LIBUSB_SUCCESS = 0;
+ public static final int LIBUSB_ERROR_IO = -1;
+ public static final int LIBUSB_ERROR_INVALID_PARAM = -2;
+ public static final int LIBUSB_ERROR_ACCESS = -3;
+ public static final int LIBUSB_ERROR_NO_DEVICE = -4;
+ public static final int LIBUSB_ERROR_NOT_FOUND = -5;
+ public static final int LIBUSB_ERROR_BUSY = -6;
+ public static final int LIBUSB_ERROR_TIMEOUT = -7;
+ public static final int LIBUSB_ERROR_OVERFLOW = -8;
+ public static final int LIBUSB_ERROR_PIPE = -9;
+ public static final int LIBUSB_ERROR_INTERRUPTED = -10;
+ public static final int LIBUSB_ERROR_NO_MEM = -11;
+ public static final int LIBUSB_ERROR_NOT_SUPPORTED = -12;
+ public static final int LIBUSB_ERROR_OTHER = -99;
+
+ /**
+ * Set message verbosity.
+ *
+ * - Level 0: no messages ever printed by the library (default)
+ * - Level 1: error messages are printed to stderr
+ * - Level 2: warning and error messages are printed to stderr
+ * - Level 3: informational messages are printed to stdout, warning and
+ * error messages are printed to stderr
+ *
+ *
+ * The default level is 0, which means no messages are ever printed. If you
+ * choose to increase the message verbosity level, ensure that your
+ * application does not close the stdout/stderr file descriptors.
+ *
+ * You are advised to set level 3. libusb is conservative with its message
+ * logging and most of the time, will only log messages that explain error
+ * conditions and other oddities. This will help you debug your software.
+ *
+ * If the LIBUSB_DEBUG environment variable was set when libusb was
+ * initialized, this function does nothing: the message verbosity is fixed
+ * to the value in the environment variable.
+ *
+ * If libusb was compiled without any message logging, this function does
+ * nothing: you'll never get any messages.
+ *
+ * If libusb was compiled with verbose debug message logging, this function
+ * does nothing: you'll always get messages from all levels.
+ *
+ *
+ * @param ctx
+ * the context to operate on, or NULL for the default context
+ * @param level
+ * debug level to set
+ */
+
+ public static native void libusb_set_debug(long ctx, int level);
+
+ /**
+ * Initialize libusb.
+ *
+ * This function must be called before calling any other libusb function.
+ *
+ *
+ * @return a context to operate on
+ * or a LIBUSB_ERROR code on failure
+ */
+ public static native long libusb_init();
+
+ /**
+ * Deinitialize libusb.
+ *
+ * Should be called after closing all open devices and before your
+ * application terminates.
+ *
+ *
+ * @param ctx
+ * the context to deinitialize, or NULL for the default context
+ */
+ public static native void libusb_exit(long ctx);
+
+ /**
+ * Returns a list of USB devices currently attached to the system.
+ *
+ * This is your entry point into finding a USB device to operate.
+ *
+ *
+ * @param ctx
+ * the context to operate on, or NULL for the default context
+ *
+ * @return Usb_Devices currently attached to the system
+ * if no device is attached the devnum of the returned device is set
+ * to -1
+ * or NULL if a failure occurs
+ */
+ public static native Usb_Device libusb_get_device_list(long ctx);
+
+ /**
+ * Get the number of the bus that a device is connected to.
+ *
+ * @param dev a device
+ * @return the bus number
+ */
+ public static native short libusb_get_bus_number(Usb_Device dev);
+
+ /**
+ * Calculate the maximum packet size which a specific endpoint is capable is
+ * sending or receiving in the duration of 1 microframe.
+ *
+ * Only the active configution is examined. The calculation is based on the
+ * wMaxPacketSize field in the endpoint descriptor as described in section
+ * 9.6.6 in the USB 2.0 specifications.
+ *
+ * If acting on an isochronous or interrupt endpoint, this function will
+ * multiply the value found in bits 0:10 by the number of transactions per
+ * microframe (determined by bits 11:12). Otherwise, this function just
+ * returns the numeric value found in bits 0:10.
+ *
+ * This function is useful for setting up isochronous transfers, for example
+ * you might pass the return value from this function to
+ * libusb_set_iso_packet_lengths() in order to set the length
+ * field of every isochronous packet in a transfer.
+ *
+ * Since libusb v1.0.3.
+ *
+ * This functionality is not available on Windows-Systems
+ *
+ *
+ * @param dev
+ * a device
+ * @param endpoint
+ * address of the endpoint in question
+ * @return the maximum packet size which can be sent/received on this
+ * endpoint
+ * LIBUSB_ERROR_NOT_FOUND if the endpoint does not exist
+ * LIBUSB_ERROR_OTHER on other failure
+ * TODO wenn funktion impl. richtig verlinken @see
+ * libusb_set_iso_packet_lengths()
+ */
+
+ public static native int libusb_get_max_iso_packet_size(Usb_Device dev,
+ short endpoint);
+
+ /**
+ * Increment the reference count of a device.
+ *
+ * @param dev
+ * the device to reference
+ * @return the same device
+ */
+ public static native Usb_Device libusb_ref_device(Usb_Device dev);
+
+ /**
+ * Decrement the reference count of a device.
+ *
+ * If the decrement operation causes the reference count to reach zero, the
+ * device shall be destroyed.
+ *
+ *
+ * @param dev
+ * the device to unreference
+ */
+
+ public static native void libusb_unref_device(Usb_Device dev);
+
+ /**
+ * Open a device and obtain a device handle.
+ *
+ * A handle allows you to perform I/O on the device in question.
+ *
+ * Internally, this function adds a reference to the device and makes it
+ * available to you through libusb_get_device(). This reference
+ * is removed during libusb_close().
+ *
+ * This is a non-blocking function; no requests are sent over the bus.
+ *
+ *
+ * @param dev
+ * the device to open
+ *
+ * @return a device handler
+ *
+ * @see #libusb_get_device(long)
+ */
+ public static native long libusb_open(Usb_Device dev);
+
+ /**
+ * Convenience function for finding a device with a particular
+ * idVendor/idProduct combination.
+ *
+ * This function is intended for those scenarios where you are using libusb
+ * to knock up a quick test application - it allows you to avoid calling
+ * libusb_get_device_list() and worrying about
+ * traversing/freeing the list.
+ *
+ * This function has limitations and is hence not intended for use in real
+ * applications: if multiple devices have the same IDs it will only give you
+ * the first one, etc.
+ *
+ * @param ctx
+ * the context to operate on, or NULL for the default context
+ * @param vendor_id
+ * the idVendor value to search for
+ * @param product_id
+ * the idProduct value to search for
+ * @return a handle for the first found device, or NULL on error or if the
+ * device could not be found.
+ * @see #libusb_get_device_list(long)
+ */
+ public static native long libusb_open_device_with_vid_pid(long ctx,
+ int vendor_id, int product_id);
+
+ /**
+ * Close a device handle.
+ *
+ * Should be called on all open handles before your application exits.
+ *
+ * Internally, this function destroys the reference that was added by
+ * libusb_open() on the given device.
+ *
+ * This is a non-blocking function; no requests are sent over the bus.
+ *
+ *
+ * @param dev_handle
+ * the handle to close
+ */
+ public static native void libusb_close(long dev_handle);
+
+ /**
+ * Get the underlying device for a handle.
+ *
+ * This function does not modify the reference count of the returned device,
+ * so do not feel compelled to unreference it when you are done.
+ *
+ *
+ * @param dev_handle
+ * a device handle
+ * @return the underlying {@link Usb_Device}
+ */
+ public static native Usb_Device libusb_get_device(long dev_handle);
+
+ /**
+ * Determine the bConfigurationValue of the currently active configuration.
+ *
+ * You could formulate your own control request to obtain this information,
+ * but this function has the advantage that it may be able to retrieve the
+ * information from operating system caches (no I/O involved).
+ *
+ * If the OS does not cache this information, then this function will block
+ * while a control transfer is submitted to retrieve the information.
+ *
+ * This function will return a value of 0 if the device is in unconfigured
+ * state.
+ *
+ *
+ * @param dev_handle
+ * a device handle
+ * @return bConfigurationValue of the currently active configuration
+ *
+ */
+ public static native byte libusb_get_configuration(long dev_handle);
+
+ /**
+ * Set the active configuration for a device.
+ *
+ * The operating system may or may not have already set an active
+ * configuration on the device. It is up to your application to ensure the
+ * correct configuration is selected before you attempt to claim interfaces
+ * and perform other operations.
+ *
+ * If you call this function on a device already configured with the
+ * selected configuration, then this function will act as a lightweight
+ * device reset: it will issue a SET_CONFIGURATION request using the current
+ * configuration, causing most USB-related device state to be reset
+ * (altsetting reset to zero, endpoint halts cleared, toggles reset).
+ *
+ * You cannot change/reset configuration if your application has claimed
+ * interfaces - you should free them with
+ * {@link #libusb_release_interface(long, int)} first. You cannot
+ * change/reset configuration if other applications or drivers have claimed
+ * interfaces.
+ *
+ * A configuration value of -1 will put the device in unconfigured state.
+ * The USB specifications state that a configuration value of 0 does this,
+ * however buggy devices exist which actually have a configuration 0.
+ *
+ * You should always use this function rather than formulating your own
+ * SET_CONFIGURATION control request. This is because the underlying
+ * operating system needs to know when such changes happen.
+ *
+ * This is a blocking function.
+ *
+ *
+ * @param dev_handle
+ * a device handle
+ * @param configuration
+ * the bConfigurationValue of the configuration you wish to
+ * activate, or -1 if you wish to put the device in unconfigured
+ * state
+ * @return 0 on success
+ * LIBUSB_ERROR_NOT_FOUND if the requested configuration does not
+ * exist
+ * LIBUSB_ERROR_BUSY if interfaces are currently claimed
+ * LIBUSB_ERROR_NO_DEVICE if the device has been disconnected
+ * another LIBUSB_ERROR code on other failure
+ */
+ public static native int libusb_set_configuration(long dev_handle,
+ int configuration);
+
+ /**
+ * Claim an interface on a given device handle.
+ *
+ * You must claim the interface you wish to use before you can perform I/O
+ * on any of its endpoints.
+ *
+ * It is legal to attempt to claim an already-claimed interface, in which
+ * case libusb just returns 0 without doing anything.
+ *
+ * Claiming of interfaces is a purely logical operation, it does not cause
+ * any requests to be sent over the bus. Interface claiming is used to
+ * instruct the underlying operating system that your application wishes to
+ * take ownership of the interface.
+ *
+ * This is a non-blocking function.
+ *
+ *
+ * @param dev_handle
+ * a device handle
+ * @param interface_number
+ * the bInterfaceNumber of the interface you wish to claim
+ * @return 0 on success
+ * LIBUSB_ERROR_NOT_FOUND if the interface was not claimed
+ * LIBUSB_ERROR_NO_DEVICE if the device has been disconnected
+ * LIBUSB_ERROR_BUSY if another program or driver has claimed the
+ * interface
+ * another LIBUSB_ERROR code on other failure
+ */
+ public static native int libusb_claim_interface(long dev_handle,
+ int interface_number);
+
+ /**
+ * Release an interface previously claimed with
+ * {@link #libusb_claim_interface(long, int)}.
+ *
+ * You should release all claimed interfaces before closing a device handle.
+ *
+ * This is a blocking function. A SET_INTERFACE control request will be sent
+ * to the device, resetting interface state to the first alternate setting.
+ *
+ *
+ * @param dev_handle
+ * a device handle
+ * @param interface_number
+ * the bInterfaceNumber of the previously-claimed interface
+ * @return 0 on success
+ * LIBUSB_ERROR_NOT_FOUND if the interface was not claimed
+ * LIBUSB_ERROR_NO_DEVICE if the device has been disconnected
+ * another LIBUSB_ERROR code on other failure
+ */
+ public static native int libusb_release_interface(long dev_handle,
+ int interface_number);
+
+ /**
+ * Activate an alternate setting for an interface.
+ *
+ * The interface must have been previously claimed with
+ *{@link #libusb_claim_interface(long, int)}.
+ *
+ * You should always use this function rather than formulating your own
+ * SET_INTERFACE control request. This is because the underlying operating
+ * system needs to know when such changes happen.
+ *
+ * This is a blocking function.
+ *
+ *
+ * @param dev_handle
+ * a device handle
+ * @param interface_number
+ * the bInterfaceNumber of the previously-claimed interface
+ * @param alternate_setting
+ * the bAlternateSetting of the alternate setting to activate
+ * @return 0 on success
+ * LIBUSB_ERROR_NOT_FOUND if the interface was not claimed, or the
+ * requested alternate setting does not exist
+ * LIBUSB_ERROR_NO_DEVICE if the device has been disconnected
+ * another LIBUSB_ERROR code on other failure
+ */
+ public static native int libusb_set_interface_alt_setting(long dev_handle,
+ int interface_number, int alternate_setting);
+
+ /**
+ * Clear the halt/stall condition for an endpoint.
+ *
+ * Endpoints with halt status are unable to receive or transmit data until
+ * the halt condition is stalled.
+ *
+ * You should cancel all pending transfers before attempting to clear the
+ * halt condition.
+ *
+ * This is a blocking function.
+ *
+ *
+ * @param dev_handle
+ * a device handle
+ * @param endpoint
+ * the endpoint to clear halt status
+ * @return 0 on success
+ * LIBUSB_ERROR_NOT_FOUND if the endpoint does not exist
+ * LIBUSB_ERROR_NO_DEVICE if the device has been disconnected
+ * another LIBUSB_ERROR code on other failure
+ */
+ public static native int libusb_clear_halt(long dev_handle, short endpoint);
+
+ /**
+ * Perform a USB port reset to reinitialize a device.
+ *
+ * The system will attempt to restore the previous configuration and
+ * alternate settings after the reset has completed.
+ *
+ * If the reset fails, the descriptors change, or the previous state cannot
+ * be restored, the device will appear to be disconnected and reconnected.
+ * This means that the device handle is no longer valid (you should close
+ * it) and rediscover the device. A return code of LIBUSB_ERROR_NOT_FOUND
+ * indicates when this is the case.
+ *
+ * This is a blocking function which usually incurs a noticeable delay.
+ *
+ *
+ * @param dev_handle
+ * a handle of the device to reset
+ * @return 0 on success
+ * LIBUSB_ERROR_NOT_FOUND if re-enumeration is required, or if the
+ * device has been disconnected
+ * another LIBUSB_ERROR code on other failure
+ */
+ public static native int libusb_reset_device(long dev_handle);
+
+ /**
+ * Determine if a kernel driver is active on an interface.
+ *
+ * If a kernel driver is active, you cannot claim the interface, and libusb
+ * will be unable to perform I/O.
+ *
+ *
+ * @param dev_handle
+ * a device handle
+ * @param interface_number
+ * the interface to check
+ * @return 0 if no kernel driver is active
+ * 1 if a kernel driver is active
+ * LIBUSB_ERROR_NO_DEVICE if the device has been disconnected
+ * another LIBUSB_ERROR code on other failure
+ * @see #libusb_detach_kernel_driver(long, int)
+ */
+ public static native int libusb_kernel_driver_active(long dev_handle,
+ int interface_number);
+
+ /**
+ * Detach a kernel driver from an interface.
+ *
+ * If successful, you will then be able to claim the interface and perform
+ * I/O.
+ *
+ *
+ * @param dev_handle
+ * a device handle
+ * @param interface_number
+ * the interface to detach the driver from
+ * @return 0 on success
+ * LIBUSB_ERROR_NOT_FOUND if no kernel driver was active
+ * LIBUSB_ERROR_INVALID_PARAM if the interface does not exist
+ * LIBUSB_ERROR_NO_DEVICE if the device has been disconnected
+ * another LIBUSB_ERROR code on other failure
+ * @see #libusb_kernel_driver_active(long, int)
+ */
+ public static native int libusb_detach_kernel_driver(long dev_handle,
+ int interface_number);
+
+ /**
+ * Re-attach an interface's kernel driver, which was previously detached
+ * using {@link #libusb_detach_kernel_driver(long, int)}.
+ *
+ * @param dev_handle
+ * a device handle
+ * @param interface_number
+ * the interface to attach the driver from
+ * @return 0 on success
+ * LIBUSB_ERROR_NOT_FOUND if no kernel driver was active
+ * LIBUSB_ERROR_INVALID_PARAM if the interface does not exist
+ * LIBUSB_ERROR_NO_DEVICE if the device has been disconnected
+ * LIBUSB_ERROR_BUSY if the driver cannot be attached because the
+ * interface is claimed by a program or driver
+ * another LIBUSB_ERROR code on other failure
+ * @see #libusb_kernel_driver_active(long, int)
+ */
+ public static native int libusb_attach_kernel_driver(long dev_handle,
+ int interface_number);
+
+ /**
+ * Get the USB configuration descriptor for the currently active
+ * configuration.
+ *
+ * This is a non-blocking function which does not involve any requests being
+ * sent to the device.
+ *
+ *
+ * @param dev
+ * a device
+ * @return {@link Usb_Config_Descriptor}
+ */
+ public static native Usb_Config_Descriptor libusb_get_active_config_descriptor(
+ Usb_Device dev);
+
+ /**
+ * Retrieve a string descriptor in C style ASCII.
+ *
+ * Wrapper around
+ * {@link #libusb_get_string_descriptor(long, short, int, int)}. Uses the
+ * first language supported by the device.
+ *
+ * @param dev_handle
+ * a device handle
+ * @param desc_index
+ * the index of the descriptor to retrieve
+ * @param size
+ * number of charactes which will be retrieved (the length of the
+ * resulting String)
+ * @return a string which contains the string descriptor
+ */
+ public static native String libusb_get_string_descriptor_ascii(
+ long dev_handle, short desc_index, int size);
+
+ /**
+ * Retrieve a descriptor from the default control pipe.
+ *
+ * This is a convenience function which formulates the appropriate control
+ * message to retrieve the descriptor.
+ *
+ * @param dev_handle
+ * a device handle
+ * @param desc_type
+ * the descriptor type
+ * @param desc_index
+ * the index of the descriptor to retrieve
+ * @param size
+ * number of bytes which will be retrieved (the length of the
+ * resulting byte[])
+ * @return a byte[] which contains the descriptor or null on failure
+ *
+ */
+ public static native byte[] libusb_get_descriptor(long dev_handle,
+ int desc_type, short desc_index, int size);
+
+ /**
+ * Retrieve a descriptor from a device.
+ *
+ * This is a convenience function which formulates the appropriate control
+ * message to retrieve the descriptor. The string returned is Unicode, as
+ * detailed in the USB specifications.
+ *
+ * @param dev_handle
+ * a device handle
+ * @param desc_index
+ * the index of the descriptor to retrieve
+ * @param langid
+ * the language ID for the string descriptor
+ * @param size
+ * number of charactes which will be retrieved (the length of the
+ * resulting String)
+ * @return a string which contains the string descriptor
+ * @see #libusb_get_string_descriptor_ascii(long, short, int)
+ */
+ public static native String libusb_get_string_descriptor(long dev_handle,
+ short desc_index, int langid, int size);
+
+ /**
+ * Allocate a libusb transfer with a specified number of isochronous packet
+ * descriptors.
+ *
+ * The returned transfer is pre-initialized for you. When the new transfer
+ * is no longer needed, it should be freed with
+ * libusb_free_transfer().
+ *
+ * Transfers intended for non-isochronous endpoints (e.g. control, bulk,
+ * interrupt) should specify an iso_packets count of zero.
+ *
+ * For transfers intended for isochronous endpoints, specify an appropriate
+ * number of packet descriptors to be allocated as part of the transfer. The
+ * returned transfer is not specially initialized for isochronous I/O you
+ * are still required to set the num_iso_packets and type
+ * fields accordingly.
+ *
+ * It is safe to allocate a transfer with some isochronous packets and then
+ * use it on a non-isochronous endpoint. If you do this, ensure that at time
+ * of submission, num_iso_packets is 0 and that type is set appropriately.
+ *
+ * @param iso_packets
+ * number of isochronous packet descriptors to allocate
+ * @return a newly allocated transfernumber, or NULL on error
+ */
+ public static native long libusb_alloc_transfer(int iso_packets);
+
+ /**
+ * Free a transfer.
+ *
+ * This should be called for all transfers allocated with
+ * libusb_alloc_transfer().
+ *
+ * It is legal to call this function with a NULL transfer. In this case, the
+ * function will simply return safely.
+ *
+ * It is not legal to free an active transfer (one which has been submitted
+ * and has not yet completed).
+ *
+ *
+ * @param transfernumber
+ * the transfer to free
+ */
+ public static native void libusb_free_transfer(long transfernumber);
+
+ /**
+ * Submit a transfer.
+ *
+ * This function will fire off the USB transfer and then return immediately.
+ *
+ *
+ * @param transfernumber
+ * the transfer to submit
+ * @return 0 on success
+ * LIBUSB_ERROR_NO_DEVICE if the device has been disconnected
+ * LIBUSB_ERROR_BUSY if the transfer has already been submitted.
+ * another LIBUSB_ERROR code on other failure
+ */
+ public static native int libusb_submit_transfer(long transfernumber);
+
+ /**
+ * Asynchronously cancel a previously submitted transfer.
+ *
+ * This function returns immediately, but this does not indicate
+ * cancellation is complete. Libusb_event will be invoked at some later time
+ * to notify you.
+ *
+ * @param transfernumber
+ * a transfer
+ * @return 0 on success
+ * LIBUSB_ERROR_NOT_FOUND if the transfer is already complete or
+ * cancelled.
+ * a LIBUSB_ERROR code on failure
+ */
+ public static native int libusb_cancel_transfer(long transfernumber);
+
+ /**
+ * Get the data section of a control transfer.
+ *
+ * This convenience function is here to remind you that the data does not
+ * start until 8 bytes into the actual buffer, as the setup packet comes
+ * first.
+ *
+ * Calling this function only makes sense from a transfer event handler, or
+ * situations where you have already allocated a suitably sized buffer.
+ *
+ * @param transfernumber
+ * a transfer
+ * @return the data section from the transfer
+ */
+ public static native byte[] libusb_control_transfer_get_data(
+ long transfernumber);
+
+ /**
+ * Get the control setup packet of a control transfer.
+ *
+ * This convenience function is here to remind you that the control setup
+ * occupies the first 8 bytes of the transfer data buffer.
+ *
+ * Calling this function only makes sense from a transfer event handler, or
+ * situations where you have already allocated a suitably sized buffer at
+ * transfer->buffer.
+ *
+ * @param transfernumber
+ * a transfer
+ * @return the setup packet from the transfer
+ */
+ public static native byte[] libusb_control_transfer_get_setup(
+ long transfernumber);
+
+ /**
+ * Helper function to populate the setup packet (first 8 bytes of the data
+ * buffer) for a control transfer.
+ *
+ * @param bmRequestType
+ * @param bRequest
+ * @param wValue
+ * @param wIndex
+ * @param wLength
+ * @return the setup packet
+ */
+ public static native byte[] libusb_fill_control_setup(int bmRequestType,
+ int bRequest, int wValue, int wIndex, int wLength);
+
+ /**
+ * Helper function to populate the required libusb_transfer fields for a
+ * control transfer.
+ *
+ * If you pass a transfer buffer to this function, the first 8 bytes will be
+ * interpreted as a control setup packet, and the wLength field will be used
+ * to automatically populate the length field of the transfer. Therefore the
+ * recommended approach is:
+ *
+ * 1. Call libusb_fill_control_setup()
+ * 2. Allocate a suitably sized data buffer (including space for control
+ * setup)
+ * 3. Put the retrieved setup packet into the firste 8 byte of the data
+ * buffer.
+ * 4. If this is a host-to-device transfer with a data stage, put the data
+ * in place after the setup packet
+ * 5. Call this function
+ * 6. Call libusb_submit_transfer()
+ *
+ * It is also legal to pass a NULL buffer to this function, in which case
+ * this function will not attempt to populate the length field. Remember
+ * that you must then populate the buffer and length fields later.
+ *
+ * @param transfernumber
+ * transfer to populate
+ * @param dev_handle
+ * handle of the device that
+ * @param buffer
+ * data buffer. If provided, this function will interpret the
+ * first 8 bytes as a setup packet and infer the transfer length
+ * from that.
+ * @param timeout
+ * timeout for the transfer in milliseconds
+ */
+ public static native void libusb_fill_control_transfer(long transfernumber,
+ long dev_handle, byte[] buffer, int timeout);
+
+ /**
+ * Helper function to populate the required libusb_transfer fields for a
+ * bulk transfer.
+ *
+ * @param transfernumber
+ * the transfer to populate
+ * @param dev_handle
+ * handle of the device that will handle the transfer
+ * @param endpoint
+ * address of the endpoint where this transfer will be sent
+ * @param buffer
+ * data buffer
+ * @param length
+ * length of data buffer
+ * @param timeout
+ * timeout for the transfer in milliseconds
+ */
+ public static native void libusb_fill_bulk_transfer(long transfernumber,
+ long dev_handle, byte endpoint, byte[] buffer, int length,
+ int timeout);
+
+ /**
+ * Helper function to populate the required libusb_transfer fields for an
+ * interrupt transfer.
+ *
+ * @param transfernumber
+ * the transfer to populate
+ * @param dev_handle
+ * handle of the device that will handle the transfer
+ * @param endpoint
+ * address of the endpoint where this transfer will be sent
+ * @param buffer
+ * data buffer
+ * @param length
+ * length of data buffer
+ * @param timeout
+ * timeout for the transfer in milliseconds
+ */
+ public static native void libusb_fill_interrupt_transfer(
+ long transfernumber, long dev_handle, byte endpoint, byte[] buffer,
+ int length, int timeout);
+
+ /**
+ * Helper function to populate the required libusb_transfer fields for an
+ * isochronous transfer.
+ *
+ * @param transfernumber
+ * the transfer to populate
+ * @param dev_handle
+ * handle of the device that will handle the transfer
+ * @param endpoint
+ * address of the endpoint where this transfer will be sent
+ * @param buffer
+ * data buffer
+ * @param length
+ * length of data buffer
+ * @param num_iso_packets
+ * the number of isochronous packets
+ * @param timeout
+ * timeout for the transfer in milliseconds
+ */
+ public static native void libusb_fill_iso_transfer(long transfernumber,
+ long dev_handle, byte endpoint, byte[] buffer, int length,
+ int num_iso_packets, int timeout);
+
+ /**
+ * Convenience function to set the length of all packets in an isochronous
+ * transfer, based on the num_iso_packets field in the transfer structure.
+ *
+ * @param transfer
+ * a transfer
+ * @param length
+ * the length to set in each isochronous packet descriptor
+ */
+ public static native void libusb_set_iso_packet_lengths(long transfer,
+ int length);
+
+ /**
+ * Convenience function to locate the position of an isochronous packet
+ * within the buffer of an isochronous transfer.
+ *
+ * This is a thorough function which loops through all preceding packets,
+ * accumulating their lengths to find the position of the specified packet.
+ * Typically you will assign equal lengths to each packet in the transfer,
+ * and hence the above method is sub-optimal. You may wish to use
+ * libusb_get_iso_packet_buffer_simple() instead.
+ *
+ *
+ * @param transfer
+ * a transfer
+ * @param packet
+ * the packet to return
+ * @return the packet buffer inside the transfer buffer, or NULL if the
+ * packet does not exist
+ */
+ public static native byte[] libusb_get_iso_packet_buffer(long transfer,
+ int packet);
+
+ /**
+ * Convenience function to locate the position of an isochronous packet
+ * within the buffer of an isochronous transfer, for transfers where each
+ * packet is of identical size.
+ *
+ * This function relies on the assumption that every packet within the
+ * transfer is of identical size to the first packet. Calculating the
+ * location of the packet buffer is then just a simple calculation: buffer +
+ * (packet_size * packet)
+ *
+ * Do not use this function on transfers other than those that have
+ * identical packet lengths for each packet.
+ *
+ * @param transfernumber
+ * a transfer
+ * @param packet
+ * he packet to return
+ * @return the packet buffer inside the transfer buffer, or NULL if the
+ * packet does not exist.
+ */
+ public static native byte[] libusb_get_iso_packet_buffer_simple(
+ long transfernumber, int packet);
+
+ /**
+ * Attempt to acquire the event handling lock.
+ *
+ * This lock is used to ensure that only one thread is monitoring libusb
+ * event sources at any one time.
+ *
+ * You only need to use this lock if you are developing an application which
+ * calls poll() or select() on libusb's file descriptors directly. If you
+ * stick to libusb's event handling loop functions (e.g.
+ * libusb_handle_events()) then you do not need to be concerned
+ * with this locking.
+ *
+ * While holding this lock, you are trusted to actually be handling events.
+ * If you are no longer handling events, you must call
+ * libusb_unlock_events() as soon as possible.
+ *
+ * @param ctx
+ * the context to operate on, or NULL for the default context
+ * @return 0 if the lock was obtained successfully
+ * 1 if the lock was not obtained (i.e. another thread holds the
+ * lock)
+ */
+ public static native int libusb_try_lock_events(long ctx);
+
+ /**
+ * Acquire the event handling lock, blocking until successful acquisition if
+ * it is contended.
+ *
+ * This lock is used to ensure that only one thread is monitoring libusb
+ * event sources at any one time.
+ *
+ * You only need to use this lock if you are developing an application which
+ * calls poll() or select() on libusb's file descriptors directly. If you
+ * stick to libusb's event handling loop functions (e.g.
+ * libusb_handle_events()) then you do not need to be concerned
+ * with this locking.
+ *
+ * While holding this lock, you are trusted to actually be handling events.
+ * If you are no longer handling events, you must call
+ * libusb_unlock_events() as soon as possible.
+ *
+ * @param ctx
+ * the context to operate on, or NULL for the default context
+ */
+ public static native void libusb_lock_events(long ctx);
+
+ /**
+ * Release the lock previously acquired with
+ * libusb_try_lock_events() or
+ * libusb_lock_events().
+ *
+ * Releasing this lock will wake up any threads blocked on
+ * libusb_wait_for_event().
+ *
+ * @param ctx
+ * the context to operate on, or NULL for the default context
+ */
+ public static native void libusb_unlock_events(long ctx);
+
+ /**
+ * Determine if it is still OK for this thread to be doing event handling.
+ *
+ * Sometimes, libusb needs to temporarily pause all event handlers, and this
+ * is the function you should use before polling file descriptors to see if
+ * this is the case.
+ *
+ * If this function instructs your thread to give up the events lock, you
+ * should just continue the usual logic. On the next iteration, your thread
+ * will fail to obtain the events lock, and will hence become an event
+ * waiter.
+ *
+ * This function should be called while the events lock is held: you don't
+ * need to worry about the results of this function if your thread is not
+ * the current event handler.
+ *
+ * @param ctx
+ * the context to operate on, or NULL for the default context
+ * @return 1 if event handling can start or continue
+ * 0 if this thread must give up the events lock
+ */
+ public static native int libusb_event_handling_ok(long ctx);
+
+ /**
+ * Determine if an active thread is handling events (i.e. if anyone is
+ * holding the event handling lock).
+ *
+ * @param ctx
+ * the context to operate on, or NULL for the default context
+ * @return 1 if a thread is handling events
+ * 0 if there are no threads currently handling events
+ */
+ public static native int libusb_event_handler_active(long ctx);
+
+ /**
+ * Acquire the event waiters lock.
+ *
+ * This lock is designed to be obtained under the situation where you want
+ * to be aware when events are completed, but some other thread is event
+ * handling so calling libusb_handle_events() is not allowed.
+ *
+ * You then obtain this lock, re-check that another thread is still handling
+ * events, then call libusb_wait_for_event().
+ *
+ * You only need to use this lock if you are developing an application which
+ * calls poll() or select() on libusb's file descriptors directly, and may
+ * potentially be handling events from 2 threads simultaenously. If you
+ * stick to libusb's event handling loop functions (e.g.
+ * libusb_handle_events()) then you do not need to be concerned
+ * with this locking.
+ *
+ * @param ctx
+ * the context to operate on, or NULL for the default context
+ */
+ public static native void libusb_lock_event_waiters(long ctx);
+
+ /**
+ * Release the event waiters lock.
+ *
+ * @param ctx
+ * the context to operate on, or NULL for the default context
+ */
+ public static native void libusb_unlock_event_waiters(long ctx);
+
+ /**
+ * Wait for another thread to signal completion of an event.
+ *
+ * Must be called with the event waiters lock held, see
+ * libusb_lock_event_waiters().
+ *
+ * This function will block until any of the following conditions are met:
+ *
+ * 1. The timeout expires
+ * 2. A transfer completes
+ * 3. A thread releases the event handling lock through
+ * libusb_unlock_events()
+ *
+ * Condition 1 is obvious. Condition 2 unblocks your thread after the
+ * callback for the transfer has completed. Condition 3 is important because
+ * it means that the thread that was previously handling events is no longer
+ * doing so, so if any events are to complete, another thread needs to step
+ * up and start event handling.
+ *
+ * This function releases the event waiters lock before putting your thread
+ * to sleep, and reacquires the lock as it is being woken up.
+ *
+ * @param ctx
+ * the context to operate on, or NULL for the default context
+ * @param timeval
+ * maximum timeout in seconds for this blocking function. 0
+ * seconds indicates unlimited timeout
+ * @return 0 after a transfer completes or another thread stops event
+ * handling
+ * 1 if the timeout expired
+ */
+ public static native int libusb_wait_for_event(long ctx, long timeval);
+
+ /**
+ * Handle any pending events.
+ *
+ * libusb determines "pending events" by checking if any timeouts have
+ * expired and by checking the set of file descriptors for activity.
+ *
+ * If a zero timeval is passed, this function will handle any
+ * already-pending events and then immediately return in non-blocking style.
+ *
+ * If a non-zero timeval is passed and no events are currently pending, this
+ * function will block waiting for events to handle up until the specified
+ * timeout. If an event arrives or a signal is raised, this function will
+ * return early.
+ *
+ * @param ctx
+ * the context to operate on, or NULL for the default context
+ * @param timeval
+ * the maximum time to block waiting for events, or zero for
+ * non-blocking mode
+ * @return 0 on success, or a LIBUSB_ERROR code on failure
+ */
+ public static native int libusb_handle_events_timeout(long ctx, long timeval);
+
+ /**
+ * Handle any pending events in blocking mode with a sensible timeout.
+ *
+ * This timeout is currently hardcoded at 2 seconds but we may change this
+ * if we decide other values are more sensible. For finer control over
+ * whether this function is blocking or non-blocking, or the maximum
+ * timeout, use libusb_handle_events_timeout() instead.
+ *
+ * @param ctx
+ * the context to operate on, or NULL for the default context
+ * @return 0 on success, or a LIBUSB_ERROR code on failure
+ */
+ public static native int libusb_handle_events(long ctx);
+
+ /**
+ * Handle any pending events by polling file descriptors, without checking
+ * if any other threads are already doing so.
+ *
+ * Must be called with the event lock held, see
+ * libusb_lock_events().
+ *
+ * This function is designed to be called under the situation where you have
+ * taken the event lock and are calling poll()/select() directly on libusb's
+ * file descriptors (as opposed to using libusb_handle_events()
+ * or similar). You detect events on libusb's descriptors, so you then call
+ * this function with a zero timeout value (while still holding the event
+ * lock).
+ *
+ * @param ctx
+ * the context to operate on, or NULL for the default context
+ * @param timeval
+ * the maximum time in seconds to block waiting for events, or
+ * zero for non-blocking mode
+ * @return 0 on success, or a LIBUSB_ERROR code on failure
+ */
+ public static native int libusb_handle_events_locked(long ctx, long timeval);
+
+ /**
+ * Determines whether your application must apply special timing
+ * considerations when monitoring libusb's file descriptors.
+ *
+ * This function is only useful for applications which retrieve and poll
+ * libusb's file descriptors in their own main loop (The more advanced
+ * option).
+ *
+ * Ordinarily, libusb's event handler needs to be called into at specific
+ * moments in time (in addition to times when there is activity on the file
+ * descriptor set). The usual approach is to use
+ * libusb_get_next_timeout() to learn about when the next
+ * timeout occurs, and to adjust your poll()/select() timeout accordingly so
+ * that you can make a call into the library at that time.
+ *
+ * Some platforms supported by libusb do not come with this baggage - any
+ * events relevant to timing will be represented by activity on the file
+ * descriptor set, and libusb_get_next_timeout() will always
+ * return 0. This function allows you to detect whether you are running on
+ * such a platform.
+ *
+ * Since v1.0.5.
+ *
+ * @param ctx
+ * the context to operate on, or NULL for the default context
+ * @return 0 if you must call into libusb at times determined by
+ * libusb_get_next_timeout(), or 1 if all timeout
+ * events are handled internally or through regular activity on the
+ * file descriptors.
+ */
+ public static native int libusb_pollfds_handle_timeouts(long ctx);
+
+ /**
+ * Determine the next internal timeout that libusb needs to handle.
+ *
+ * You only need to use this function if you are calling poll() or select()
+ * or similar on libusb's file descriptors yourself - you do not need to use
+ * it if you are calling libusb_handle_events() or a variant directly.
+ *
+ * You should call this function in your main loop in order to determine how
+ * long to wait for select() or poll() to return results. libusb needs to be
+ * called into at this timeout, so you should use it as an upper bound on
+ * your select() or poll() call.
+ *
+ * When the timeout has expired, call into libusb_handle_events_timeout()
+ * (perhaps in non-blocking mode) so that libusb can handle the timeout.
+ *
+ * This function may return an zero timevalue. If this is the case, it
+ * indicates that libusb has a timeout that has already expired so you
+ * should call libusb_handle_events_timeout() or similar immediately. A
+ * return code of -999 indicates that there are no pending timeouts.
+ *
+ * On some platforms, this function will always returns -999 (no pending
+ * timeouts).
+ *
+ * @param ctx
+ * the context to operate on, or NULL for the default context
+ * @return -999 if there are no pending timeouts
+ * time to next timeout
+ * LIBUSB_ERROR_OTHER on failure
+ */
+ public static native int libusb_get_next_timeout(long ctx);
+
+ /**
+ * Register notification functions for file descriptor additions/removals.
+ *
+ * These functions will be invoked for every new or removed file descriptor
+ * that libusb uses as an event source.
+ *
+ * To remove notifiers, set remove TRUE.
+ *
+ * Note that file descriptors may have been added even before you register
+ * these notifiers (e.g. at libusb_init() time).
+ *
+ * Additionally, note that the removal notifier may be called during
+ * libusb_exit() (e.g. when it is closing file descriptors that
+ * were opened and added to the poll set at libusb_init()
+ * time).
+ * If you don't want this, remove the notifiers immediately before calling
+ * libusb_exit().
+ *
+ * @param ctx
+ * the context to operate on, or NULL for the default context
+ * @param remove
+ * select add or remove notifiers
+ */
+ public static native void libusb_set_pollfd_notifiers(long ctx,
+ boolean remove);
+
+ /**
+ * Retrieve a array of file descriptors that should be polled by your main
+ * loop as libusb event sources.
+ *
+ *
+ * The actual list contents must not be touched.
+ *
+ * @param ctx
+ * the context to operate on, or NULL for the default context
+ * @return array of Libusb_pollfd or NULL on error
+ */
+ public static native Libusb_pollfd[] libusb_get_pollfds(long ctx);
+
+ /**
+ * Perform a USB control transfer.
+ *
+ * The direction of the transfer is inferred from the bmRequestType field of
+ * the setup packet.
+ *
+ * The wValue, wIndex and wLength fields values should be given in
+ * host-endian byte order.
+ *
+ * @param dev_handle
+ * a handle for the device to communicate with
+ * @param bmRequestType
+ * the request type field for the setup packet
+ * @param bRequest
+ * the request field for the setup packet
+ * @param wValue
+ * the value field for the setup packet
+ * @param wIndex
+ * the index field for the setup packet
+ * @param data
+ * a suitably-sized data buffer for either input or output
+ * (depending on direction bits within bmRequestType)
+ * @param wLength
+ * the length field for the setup packet. The data buffer should
+ * be at least this size.
+ * @param timeout
+ * timeout (in millseconds) that this function should wait before
+ * giving up due to no response being received. For an unlimited
+ * timeout, use value 0.
+ * @return on success, the number of bytes actually transferred
+ * LIBUSB_ERROR_TIMEOUT if the transfer timed out
+ * LIBUSB_ERROR_PIPE if the control request was not supported by the
+ * device
+ * LIBUSB_ERROR_NO_DEVICE if the device has been disconnected
+ * another LIBUSB_ERROR code on other failures
+ */
+ public static native int libusb_control_transfer(long dev_handle,
+ int bmRequestType, int bRequest, int wValue, int wIndex,
+ byte[] data, int wLength, int timeout);
+
+ /**
+ * Perform a USB bulk transfer.
+ *
+ * The direction of the transfer is inferred from the direction bits of the
+ * endpoint address.
+ *
+ * For bulk reads, the length field indicates the maximum length of data you
+ * are expecting to receive. If less data arrives than expected, this
+ * function will return that data, so be sure to check the returned value.
+ *
+ * You should also check this value for bulk writes. Not all of the data may
+ * have been written.
+ *
+ * @param dev_handle
+ * a handle for the device to communicate with
+ * @param endpoint
+ * the address of a valid endpoint to communicate with
+ * @param data
+ * a suitably-sized data buffer for either input or output
+ * (depending on endpoint)
+ * @param length
+ * for bulk writes, the number of bytes from data to be sent. for
+ * bulk reads, the maximum number of bytes to receive into the
+ * data buffer.
+ * @param timeout
+ * timeout (in millseconds) that this function should wait before
+ * giving up due to no response being received. For an unlimited
+ * timeout, use value 0.
+ * @return on success, the number of bytes actually transferred
+ * LIBUSB_ERROR_TIMEOUT if the transfer timed out
+ * LIBUSB_ERROR_PIPE if the control request was not supported by the
+ * device
+ * LIBUSB_ERROR_NO_DEVICE if the device has been disconnected
+ * another LIBUSB_ERROR code on other failures.
+ */
+ public static native int libusb_bulk_transfer(long dev_handle,
+ byte endpoint, byte[] data, int length, int timeout);
+
+ /**
+ * Perform a USB interrupt transfer.
+ *
+ * The direction of the transfer is inferred from the direction bits of the
+ * endpoint address.
+ *
+ * For bulk reads, the length field indicates the maximum length of data you
+ * are expecting to receive. If less data arrives than expected, this
+ * function will return that data, so be sure to check the returned value.
+ *
+ * You should also check this value for bulk writes. Not all of the data may
+ * have been written.
+ *
+ * The default endpoint bInterval value is used as the polling interval.
+ *
+ * @param dev_handle
+ * a handle for the device to communicate with
+ * @param endpoint
+ * the address of a valid endpoint to communicate with
+ * @param data
+ * a suitably-sized data buffer for either input or output
+ * (depending on endpoint)
+ * @param length
+ * for bulk writes, the number of bytes from data to be sent. for
+ * bulk reads, the maximum number of bytes to receive into the
+ * data buffer.
+ * @param timeout
+ * timeout (in millseconds) that this function should wait before
+ * giving up due to no response being received. For an unlimited
+ * timeout, use value 0.
+ * @return on success, the number of bytes actually transferred
+ * LIBUSB_ERROR_TIMEOUT if the transfer timed out
+ * LIBUSB_ERROR_PIPE if the control request was not supported by the
+ * device
+ * LIBUSB_ERROR_NO_DEVICE if the device has been disconnected
+ * another LIBUSB_ERROR code on other failures
+ */
+ public static native int libusb_interrupt_transfer(long dev_handle,
+ byte endpoint, byte[] data, int length, int timeout);
+
+ /**
+ * Returns the error string after an error occured.
+ *
+ * @return the last error sring.
+ */
+ public static native String libusb_strerror();
+
+ static {
+ String os = System.getProperty("os.name");
+ if (os.contains("Windows")) {
+ System.loadLibrary("LibusbJava-1_0");
+ } else {
+ System.loadLibrary("usbJava-1.0");
+ }
+ }
+}
diff --git a/java/src/ch/ntb/inf/libusbJava/Libusb_event.java b/java/src/ch/ntb/inf/libusbJava/Libusb_event.java
new file mode 100644
index 0000000..5268951
--- /dev/null
+++ b/java/src/ch/ntb/inf/libusbJava/Libusb_event.java
@@ -0,0 +1,19 @@
+package ch.ntb.inf.libusbJava;
+
+public class Libusb_event {
+
+ public void transferCallback(){
+
+ }
+
+ public void fdAddedCallback(int fd){
+ System.out.println("addedCallback");
+
+ }
+
+ public void fdRemovedCallback(int fd){
+ System.out.println("removedCallback");
+
+ }
+
+}
diff --git a/java/src/ch/ntb/inf/libusbJava/Libusb_pollfd.java b/java/src/ch/ntb/inf/libusbJava/Libusb_pollfd.java
new file mode 100644
index 0000000..64c2552
--- /dev/null
+++ b/java/src/ch/ntb/inf/libusbJava/Libusb_pollfd.java
@@ -0,0 +1,7 @@
+package ch.ntb.inf.libusbJava;
+
+public class Libusb_pollfd {
+ int fd;
+ byte events;
+
+}
diff --git a/java/src/ch/ntb/inf/libusbJava/Usb_Bus.java b/java/src/ch/ntb/inf/libusbJava/Usb_Bus.java
index 7e00096..6930ee7 100644
--- a/java/src/ch/ntb/inf/libusbJava/Usb_Bus.java
+++ b/java/src/ch/ntb/inf/libusbJava/Usb_Bus.java
@@ -25,6 +25,11 @@ public class Usb_Bus {
private Usb_Device root_dev;
+ public Usb_Bus(String dirname, long location) {
+ this.dirname = dirname;
+ this.location = location;
+ }
+
/**
* Get the first device ojects of the devices linked list.
*
@@ -34,6 +39,10 @@ public class Usb_Bus {
return devices;
}
+ protected void setDevices(Usb_Device devices) {
+ this.devices = devices;
+ }
+
/**
* Returns the systems String representation of the bus.
*
@@ -52,6 +61,10 @@ public class Usb_Bus {
return next;
}
+ protected void setNext(Usb_Bus bus) {
+ next = bus;
+ }
+
/**
* Returns the previous bus object.
*
@@ -61,6 +74,10 @@ public class Usb_Bus {
return prev;
}
+ protected void setPrev(Usb_Bus bus) {
+ prev = bus;
+ }
+
/**
* Get the root device of this bus.
*
@@ -79,6 +96,10 @@ public class Usb_Bus {
return location;
}
+ protected void setLocation(long busnumber) {
+ location = busnumber;
+ }
+
@Override
public String toString() {
return "Usb_Bus " + dirname;
diff --git a/java/src/ch/ntb/inf/libusbJava/Usb_Descriptor.java b/java/src/ch/ntb/inf/libusbJava/Usb_Descriptor.java
index e08f6e1..10e183e 100644
--- a/java/src/ch/ntb/inf/libusbJava/Usb_Descriptor.java
+++ b/java/src/ch/ntb/inf/libusbJava/Usb_Descriptor.java
@@ -23,7 +23,9 @@ public class Usb_Descriptor {
/**
* Descriptor types ({@link #bDescriptorType}).
*/
- public static final int USB_DT_HID = 0x21, USB_DT_REPORT = 0x22,
+ public static final int LIBUSB_DT_DEVICE = 0x01, LIBUSB_DT_CONFIG = 0x02,
+ LIBUSB_DT_STRING = 0x03, LIBUSB_DT_INTERFACE = 0x04,
+ LIBUSB_DT_ENDPOINT = 0x05, USB_DT_HID = 0x21, USB_DT_REPORT = 0x22,
USB_DT_PHYSICAL = 0x23, USB_DT_HUB = 0x29;
/**
diff --git a/java/src/ch/ntb/inf/libusbJava/Usb_Device.java b/java/src/ch/ntb/inf/libusbJava/Usb_Device.java
index 7a3cdd3..4612176 100644
--- a/java/src/ch/ntb/inf/libusbJava/Usb_Device.java
+++ b/java/src/ch/ntb/inf/libusbJava/Usb_Device.java
@@ -45,6 +45,9 @@ public class Usb_Device {
public Usb_Bus getBus() {
return bus;
}
+ protected void setBus(Usb_Bus bus){
+ this.bus = bus;
+ }
/**
* Returns a reference to the first child.
@@ -99,6 +102,10 @@ public class Usb_Device {
public Usb_Device getNext() {
return next;
}
+
+ protected void setNext(Usb_Device dev){
+ next = dev;
+ }
/**
* Returns the number of children of this device.
@@ -117,6 +124,9 @@ public class Usb_Device {
public Usb_Device getPrev() {
return prev;
}
+ protected void setPrev(Usb_Device dev){
+ prev = dev;
+ }
@Override
public String toString() {
diff --git a/java/src/ch/ntb/inf/libusbJava/Usb_Device_Descriptor.java b/java/src/ch/ntb/inf/libusbJava/Usb_Device_Descriptor.java
index f78f717..9dc20b3 100644
--- a/java/src/ch/ntb/inf/libusbJava/Usb_Device_Descriptor.java
+++ b/java/src/ch/ntb/inf/libusbJava/Usb_Device_Descriptor.java
@@ -22,8 +22,9 @@ public class Usb_Device_Descriptor extends Usb_Descriptor {
* Device and/or interface class codes.
*/
public static final int USB_CLASS_PER_INTERFACE = 0, USB_CLASS_AUDIO = 1,
- USB_CLASS_COMM = 2, USB_CLASS_HID = 3, USB_CLASS_PRINTER = 7,
- USB_CLASS_MASS_STORAGE = 8, USB_CLASS_HUB = 9, USB_CLASS_DATA = 10,
+ USB_CLASS_COMM = 2, USB_CLASS_HID = 3, LIBUSB_CLASS_PTP = 6,
+ USB_CLASS_PRINTER = 7, USB_CLASS_MASS_STORAGE = 8,
+ USB_CLASS_HUB = 9, USB_CLASS_DATA = 10,
USB_CLASS_VENDOR_SPEC = 0xff;
private short bcdUSB;
diff --git a/java/src/ch/ntb/inf/libusbJava/Usb_Endpoint_Descriptor.java b/java/src/ch/ntb/inf/libusbJava/Usb_Endpoint_Descriptor.java
index 1284ba9..bd83147 100644
--- a/java/src/ch/ntb/inf/libusbJava/Usb_Endpoint_Descriptor.java
+++ b/java/src/ch/ntb/inf/libusbJava/Usb_Endpoint_Descriptor.java
@@ -36,15 +36,32 @@ public class Usb_Endpoint_Descriptor extends Usb_Descriptor {
/**
* Endpoint type mask (in bmAttributes).
*/
- public static final int USB_ENDPOINT_TYPE_MASK = 0x03;
+ public static final int USB_ENDPOINT_TRANSFER_TYPE_MASK = 0x03,
+ USB_ENDPOINT_ISO_SYNC_TYPE = 0x0C,
+ USB_ENDPOINT_ISO_USAGE_TYPE = 0x30;
/**
* Possible endpoint types (in bmAttributes).
*/
- public static final int USB_ENDPOINT_TYPE_CONTROL = 0,
- USB_ENDPOINT_TYPE_ISOCHRONOUS = 1, USB_ENDPOINT_TYPE_BULK = 2,
- USB_ENDPOINT_TYPE_INTERRUPT = 3;
+ public static final int USB_ENDPOINT_TRANSFER_TYPE_CONTROL = 0,
+ USB_ENDPOINT_TRANSFER_TYPE_ISOCHRONOUS = 1,
+ USB_ENDPOINT_TRANSFER_TYPE_BULK = 2,
+ USB_ENDPOINT_TRANSFER_TYPE_INTERRUPT = 3;
+ /**
+ * Possible synchronization types for isochronous endpoints.
+ */
+ public static final int USB_ENDPOINT_ISO_SYNC_TYPE_NONE = 0,
+ USB_ENDPOINT_ISO_SYNC_TYPE_ASYNC = 1,
+ USB_ENDPOINT_ISO_SYNC_TYPE_ADAPTIVE = 2,
+ USB_ENDPOINT_ISO_SYNC_TYPE_SYNC = 3;
+ /**
+ * Possible usage types for isochronous endpoints
+ */
+ public static final int USB_ENDPOINT_ISO_USAGE_TYPE_DATA = 0,
+ USB_ENDPOINT_ISO_USAGE_TYPE_FEEDBACK = 1,
+ USB_ENDPOINT_ISO_USAGE_TYPE_IMPLICIT = 2;
+
private byte bEndpointAddress;
private byte bmAttributes;
diff --git a/java/src/ch/ntb/inf/libusbJava/demo/ReadWrite.java b/java/src/ch/ntb/inf/libusbJava/demo/ReadWrite.java
index 72d61a3..e692f64 100644
--- a/java/src/ch/ntb/inf/libusbJava/demo/ReadWrite.java
+++ b/java/src/ch/ntb/inf/libusbJava/demo/ReadWrite.java
@@ -27,7 +27,7 @@ public class ReadWrite {
public static void main(String[] args) {
// get a device instance with vendor id and product id
- Device dev = USB.getDevice((short) 0x8235, (short) 0x0222);
+ Device dev = USB.getDevice((short) 0x8235, (short) 0x0100);
try {
// data to write to the device
byte[] data = new byte[] { 0, 1, 2, 3 };
@@ -41,12 +41,12 @@ public class ReadWrite {
// write some data to the device
// 0x03 is the endpoint address of the OUT endpoint 3 (from PC to
// device)
- dev.writeInterrupt(0x03, data, data.length, 2000, false);
+ dev.writeInterrupt(0x02, data, data.length, 2000, false);
// read some data from the device
// 0x84 is the endpoint address of the IN endpoint 4 (from PC to
// device)
// bit 7 (0x80) is set in case of an IN endpoint
- dev.readInterrupt(0x84, readData, readData.length, 2000, false);
+ dev.readInterrupt(0x86, readData, readData.length, 2000, false);
// log the data from the device
logData(readData);
// close the device
diff --git a/java/src/ch/ntb/inf/libusbJava/testApp/TestDevice.java b/java/src/ch/ntb/inf/libusbJava/testApp/TestDevice.java
index 8a699ed..89bca5a 100644
--- a/java/src/ch/ntb/inf/libusbJava/testApp/TestDevice.java
+++ b/java/src/ch/ntb/inf/libusbJava/testApp/TestDevice.java
@@ -44,15 +44,15 @@ public class TestDevice extends AbstractDeviceInfo {
@Override
public void initValues() {
setIdVendor((short) 0x8235);
- setIdProduct((short) 0x0222);
+ setIdProduct((short) 0x0200);
setTimeout(2000);
setConfiguration(1);
setInterface(0);
setAltinterface(-1);
setOutEPBulk(0x01);
setInEPBulk(0x82);
- setOutEPInt(0x03);
- setInEPInt(0x84);
+ setOutEPInt(0x01);
+ setInEPInt(0x82);
setSleepTimeout(2000);
setMaxDataSize(USB.FULLSPEED_MAX_BULK_PACKET_SIZE);
setMode(TransferMode.Bulk);
diff --git a/java/src/ch/ntb/inf/libusbJava/usbView/UsbTreeModel.java b/java/src/ch/ntb/inf/libusbJava/usbView/UsbTreeModel.java
index fa38f0b..2ed0bec 100644
--- a/java/src/ch/ntb/inf/libusbJava/usbView/UsbTreeModel.java
+++ b/java/src/ch/ntb/inf/libusbJava/usbView/UsbTreeModel.java
@@ -279,9 +279,7 @@ public class UsbTreeModel implements TreeModel, TreeSelectionListener {
break;
}
if (dev.getDescriptor().getIManufacturer() > 0) {
- String manufacturer = LibusbJava
- .usb_get_string_simple(handle, devDesc
- .getIManufacturer());
+ String manufacturer = LibusbJava.usb_get_string_simple(handle, devDesc.getIManufacturer());
if (manufacturer == null)
manufacturer = "unable to fetch manufacturer string";
sb.append("\tiManufacturer: " + manufacturer
diff --git a/java/src/ch/ntb/inf/libusbJava/usbView/UsbView.java b/java/src/ch/ntb/inf/libusbJava/usbView/UsbView.java
index 83fb90e..a4fba49 100644
--- a/java/src/ch/ntb/inf/libusbJava/usbView/UsbView.java
+++ b/java/src/ch/ntb/inf/libusbJava/usbView/UsbView.java
@@ -306,12 +306,12 @@ public class UsbView extends JFrame {
for (int i = 0; i < nofInEPs; i++) {
int type = inEPs[i].getBmAttributes() & 0x03;
switch (type) {
- case Usb_Endpoint_Descriptor.USB_ENDPOINT_TYPE_BULK:
+ case Usb_Endpoint_Descriptor.USB_ENDPOINT_TRANSFER_TYPE_BULK:
testDevice.setInEPBulk(inEPs[i]
.getBEndpointAddress() & 0xff);
testDevice.setInMode(TransferMode.Bulk);
break;
- case Usb_Endpoint_Descriptor.USB_ENDPOINT_TYPE_INTERRUPT:
+ case Usb_Endpoint_Descriptor.USB_ENDPOINT_TRANSFER_TYPE_INTERRUPT:
testDevice.setInEPInt(inEPs[i]
.getBEndpointAddress() & 0xff);
testDevice.setInMode(TransferMode.Interrupt);
@@ -325,12 +325,12 @@ public class UsbView extends JFrame {
for (int i = 0; i < nofOutEPs; i++) {
int type = outEPs[i].getBmAttributes() & 0x03;
switch (type) {
- case Usb_Endpoint_Descriptor.USB_ENDPOINT_TYPE_BULK:
+ case Usb_Endpoint_Descriptor.USB_ENDPOINT_TRANSFER_TYPE_BULK:
testDevice.setOutEPBulk(outEPs[i]
.getBEndpointAddress() & 0xff);
testDevice.setOutMode(TransferMode.Bulk);
break;
- case Usb_Endpoint_Descriptor.USB_ENDPOINT_TYPE_INTERRUPT:
+ case Usb_Endpoint_Descriptor.USB_ENDPOINT_TRANSFER_TYPE_INTERRUPT:
testDevice.setOutEPInt(outEPs[i]
.getBEndpointAddress() & 0xff);
testDevice.setOutMode(TransferMode.Interrupt);
diff --git a/java/test/ch/ntb/inf/libusbJava/test/DeviceTest.java b/java/test/ch/ntb/inf/libusbJava/test/DeviceTest.java
index 5dd08ad..e1a09d9 100644
--- a/java/test/ch/ntb/inf/libusbJava/test/DeviceTest.java
+++ b/java/test/ch/ntb/inf/libusbJava/test/DeviceTest.java
@@ -72,13 +72,13 @@ public class DeviceTest {
testData = new byte[devinfo.getMaxDataSize()];
readData = new byte[testData.length];
// initialise the device
- LibusbJava.usb_set_debug(255);
dev = USB.getDevice(devinfo.getIdVendor(), devinfo.getIdProduct(),
devinfo.getBusName(), devinfo.getFilename());
assertNotNull(dev);
// print the devices
LibusbJava.usb_init();
+// LibusbJava.usb_set_debug(255);
LibusbJava.usb_find_busses();
LibusbJava.usb_find_devices();
Usb_Bus bus = LibusbJava.usb_get_busses();
diff --git a/java/test/ch/ntb/inf/libusbJava/test/MemoryLeakTest.java b/java/test/ch/ntb/inf/libusbJava/test/MemoryLeakTest.java
index 9de91ab..bc70d69 100644
--- a/java/test/ch/ntb/inf/libusbJava/test/MemoryLeakTest.java
+++ b/java/test/ch/ntb/inf/libusbJava/test/MemoryLeakTest.java
@@ -65,13 +65,12 @@ public class MemoryLeakTest {
testData = new byte[devinfo.getMaxDataSize()];
readData = new byte[testData.length];
// initialise the device
- LibusbJava.usb_set_debug(255);
dev = USB.getDevice(devinfo.getIdVendor(), devinfo.getIdProduct());
assertNotNull(dev);
// print the devices
LibusbJava.usb_init();
- LibusbJava.usb_find_busses();
+// LibusbJava.usb_find_busses();
LibusbJava.usb_find_devices();
Usb_Bus bus = LibusbJava.usb_get_busses();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
diff --git a/java/test/ch/ntb/inf/libusbJava/test/TestLibUsbJava.java b/java/test/ch/ntb/inf/libusbJava/test/TestLibUsbJava.java
index 80896a6..a495590 100644
--- a/java/test/ch/ntb/inf/libusbJava/test/TestLibUsbJava.java
+++ b/java/test/ch/ntb/inf/libusbJava/test/TestLibUsbJava.java
@@ -217,10 +217,8 @@ public class TestLibUsbJava {
}
// used for debugging. 0 = no debugging, 255 = with debugging
- //
- LibusbJava.usb_set_debug(255);
-
LibusbJava.usb_init();
+ LibusbJava.usb_set_debug(255);
LibusbJava.usb_find_busses();
LibusbJava.usb_find_devices();
diff --git a/java/test/ch/ntb/inf/libusbJava/test/devices/AT90USB1287.java b/java/test/ch/ntb/inf/libusbJava/test/devices/AT90USB1287.java
index ba17351..518b7d9 100644
--- a/java/test/ch/ntb/inf/libusbJava/test/devices/AT90USB1287.java
+++ b/java/test/ch/ntb/inf/libusbJava/test/devices/AT90USB1287.java
@@ -15,15 +15,15 @@ public class AT90USB1287 extends AbstractDeviceInfo {
@Override
public void initValues() {
setIdVendor((short) 0x8235);
- setIdProduct((short) 0x0222);
+ setIdProduct((short) 0x0200);
setTimeout(2000);
setConfiguration(1);
setInterface(0);
setAltinterface(-1);
setOutEPBulk(0x01);
setInEPBulk(0x82);
- setOutEPInt(0x03);
- setInEPInt(0x84);
+ setOutEPInt(0x01);
+ setInEPInt(0x82);
setSleepTimeout(2000);
setMaxDataSize(USB.FULLSPEED_MAX_BULK_PACKET_SIZE);
setMode(TransferMode.Bulk);
diff --git a/java/version.properties b/java/version.properties
index 05bf58e..9326970 100644
--- a/java/version.properties
+++ b/java/version.properties
@@ -1,4 +1,4 @@
-#Thu Aug 24 14:28:28 CEST 2006
-version.major=0
-version.minor=5
-version.release=9
+#Tue Mar 30 10:58:35 CEST 2010
+version.major=1
+version.minor=0
+version.release=0