- Adding Roger Millischers work on the java side making libusb 1.0 run
git-svn-id: https://svn.code.sf.net/p/libusbjava/code/trunk@284 94ad28fe-ef68-46b1-9651-e7ae4fcf1c4c
This commit is contained in:
@@ -4,5 +4,6 @@
|
|||||||
<classpathentry kind="src" path="test"/>
|
<classpathentry kind="src" path="test"/>
|
||||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
|
||||||
<classpathentry kind="output" path="bin"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|||||||
@@ -20,11 +20,17 @@
|
|||||||
<arguments>
|
<arguments>
|
||||||
</arguments>
|
</arguments>
|
||||||
</buildCommand>
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>net.sf.eclipsensis.installoptions.InstallOptionsBuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
</buildSpec>
|
</buildSpec>
|
||||||
<natures>
|
<natures>
|
||||||
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
|
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
|
||||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
<nature>org.eclipse.jem.beaninfo.BeanInfoNature</nature>
|
<nature>org.eclipse.jem.beaninfo.BeanInfoNature</nature>
|
||||||
<nature>org.eclipse.pde.PluginNature</nature>
|
<nature>org.eclipse.pde.PluginNature</nature>
|
||||||
|
<nature>net.sf.eclipsensis.installoptions.InstallOptionsNature</nature>
|
||||||
</natures>
|
</natures>
|
||||||
</projectDescription>
|
</projectDescription>
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
Manifest-Version: 1.0
|
Manifest-Version: 1.0
|
||||||
Bundle-ManifestVersion: 2
|
Bundle-ManifestVersion: 2
|
||||||
Bundle-Name: Java libusb wrapper
|
Bundle-Name: Java libusb-1.0 wrapper
|
||||||
Bundle-SymbolicName: ch.ntb.usb
|
Bundle-SymbolicName: ch.ntb.inf.libusbJava
|
||||||
Bundle-Version: 1.0.2
|
Bundle-Version: 1.0.2
|
||||||
Bundle-Vendor: libusbjava.sourceforge.net
|
Bundle-Vendor: libusbjava.sourceforge.net
|
||||||
Require-Bundle: org.junit4
|
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
|
Bundle-RequiredExecutionEnvironment: J2SE-1.5
|
||||||
|
Import-Package: ch.ntb.inf.libusbJava
|
||||||
|
|||||||
12
java/UsbView.launch
Normal file
12
java/UsbView.launch
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
|
||||||
|
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
|
||||||
|
<listEntry value="/ch.ntb.inf.libusbJava/src/ch/ntb/inf/libusbJava/usbView/UsbView.java"/>
|
||||||
|
</listAttribute>
|
||||||
|
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
|
||||||
|
<listEntry value="1"/>
|
||||||
|
</listAttribute>
|
||||||
|
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="ch.ntb.inf.libusbJava.usbView.UsbView"/>
|
||||||
|
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="ch.ntb.inf.libusbJava"/>
|
||||||
|
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Djava.library.path="D:\inf-ma\libusbjava\libusbjava\LibusbJava\out;${env_var:PATH}""/>
|
||||||
|
</launchConfiguration>
|
||||||
@@ -1,4 +1 @@
|
|||||||
source.. = src/,\
|
# MTJ Build Properties
|
||||||
test/
|
|
||||||
bin.includes = META-INF/,\
|
|
||||||
.
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
<property file="version.properties" />
|
<property file="version.properties" />
|
||||||
|
|
||||||
<patternset id="classfiles">
|
<patternset id="classfiles">
|
||||||
<include name="**/usb/**/*.class" />
|
<include name="**/libusbJava/**/*.class" />
|
||||||
<exclude name="**/test/*" />
|
<exclude name="**/test/*" />
|
||||||
</patternset>
|
</patternset>
|
||||||
|
|
||||||
|
|||||||
@@ -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.name=ch.ntb.inf.libusbJava
|
||||||
project.vendor=inf.ntb.ch
|
project.vendor=inf.ntb.ch
|
||||||
project.dir.src=src
|
project.dir.src=src
|
||||||
|
|||||||
@@ -223,9 +223,9 @@ public class Device {
|
|||||||
|
|
||||||
if (dev != null) {
|
if (dev != null) {
|
||||||
long res = LibusbJava.usb_open(dev);
|
long res = LibusbJava.usb_open(dev);
|
||||||
if (res == 0) {
|
if (res <= 0) {
|
||||||
throw new USBException("LibusbJava.usb_open: "
|
throw new USBException("LibusbJava.usb_open: "
|
||||||
+ LibusbJava.usb_strerror());
|
+ LibusbJava.usb_strerror() + " (" + res + ")");
|
||||||
}
|
}
|
||||||
usbDevHandle = res;
|
usbDevHandle = res;
|
||||||
}
|
}
|
||||||
@@ -743,14 +743,20 @@ public class Device {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the device is open.<br>
|
* Check if the device is open, attached and work.<br>
|
||||||
* This checks only for a valid device handle. It doesn't check if the
|
|
||||||
* device is still attached or working.
|
|
||||||
*
|
*
|
||||||
* @return true if the device is open
|
* @return true if the device is open and work.
|
||||||
*/
|
*/
|
||||||
public boolean isOpen() {
|
public boolean isOpen() {
|
||||||
return usbDevHandle != 0;
|
if(usbDevHandle != 0){
|
||||||
|
try {
|
||||||
|
updateDescriptors();
|
||||||
|
} catch (USBException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return dev != null;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -4,32 +4,22 @@
|
|||||||
*
|
*
|
||||||
* http://libusbjava.sourceforge.net
|
* http://libusbjava.sourceforge.net
|
||||||
* This library is covered by the LGPL, read LGPL.txt for details.
|
* 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;
|
package ch.ntb.inf.libusbJava;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class represents the Java Native Interface to the shared library which
|
* This class is used as compatibility layer for libusb 0.1 projects. For new
|
||||||
* is (with some exceptions) a one-to-one representation of the libusb API.<br>
|
* projects use {@link LibusbJava1}
|
||||||
* <br>
|
|
||||||
* <h1>Project Description</h1>
|
|
||||||
* Java libusb is a Java wrapper for the libusb and libusb-win32 USB library.
|
|
||||||
*
|
|
||||||
* <a href="http://libusb.sourceforge.net/">libusb</a> aim is to create a
|
|
||||||
* library for use by user level applications to access USB devices regardless
|
|
||||||
* of OS.<br>
|
|
||||||
* <a href="http://libusb-win32.sourceforge.net/">Libusb-win32</a> is a port of
|
|
||||||
* the USB library <a href="http://libusb.sourceforge.net/">libusb</a> 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.<br>
|
|
||||||
* <br>
|
|
||||||
* The API description of this class has been copied from the <a
|
|
||||||
* href="http://libusb.sourceforge.net/documentation.html">libusb documentation</a>
|
|
||||||
* and adapted where neccessary.<br>
|
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class LibusbJava {
|
public class LibusbJava {
|
||||||
|
|
||||||
|
private static Usb_Bus busses = null;
|
||||||
|
private static long defaultCTX = 0;
|
||||||
/**
|
/**
|
||||||
* System error codes.<br>
|
* System error codes.<br>
|
||||||
* This list is not complete! For more error codes see the file 'errorno.h'
|
* This list is not complete! For more error codes see the file 'errorno.h'
|
||||||
@@ -49,15 +39,29 @@ public class LibusbJava {
|
|||||||
* @param level
|
* @param level
|
||||||
* 0 to 255
|
* 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
|
// Core
|
||||||
/**
|
/**
|
||||||
* Just like the name implies, <code>usb_init</code> sets up some internal
|
* Just like the name implies, <code>usb_init</code> sets up some internal
|
||||||
* structures. <code>usb_init</code> must be called before any other
|
* structures. <code>usb_init</code> must be called before any other libusb
|
||||||
* libusb functions.
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <code>usb_find_busses</code> will find all of the busses on the system.
|
* <code>usb_find_busses</code> 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
|
* @return the number of changes since previous call to this function (total
|
||||||
* of new busses and busses removed).
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <code>usb_find_devices</code> will find all of the devices on each bus.
|
* <code>usb_find_devices</code> 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
|
* @return the number of changes since the previous call to this function
|
||||||
* (total of new device and devices removed).
|
* (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;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <code>usb_get_busses</code> returns a tree of descriptor objects.<br>
|
* <code>usb_get_busses</code> returns a tree of descriptor objects.<br>
|
||||||
@@ -87,7 +269,9 @@ public class LibusbJava {
|
|||||||
* @return the structure of all busses and devices. <code>Note:</code> The
|
* @return the structure of all busses and devices. <code>Note:</code> The
|
||||||
* java objects are copies of the C structs.
|
* 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
|
// Device Operations
|
||||||
/**
|
/**
|
||||||
@@ -100,17 +284,22 @@ public class LibusbJava {
|
|||||||
* @return a handle used in future communication with the device. 0 if an
|
* @return a handle used in future communication with the device. 0 if an
|
||||||
* error has occurred.
|
* 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);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <code>usb_close</code> closes a device opened with
|
* <code>usb_close</code> closes a device opened with <code>usb_open</code>.
|
||||||
* <code>usb_open</code>.
|
|
||||||
*
|
*
|
||||||
* @param dev_handle
|
* @param dev_handle
|
||||||
* The handle to the device.
|
* 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
|
* Sets the active configuration of a device
|
||||||
@@ -122,8 +311,9 @@ public class LibusbJava {
|
|||||||
* bConfigurationValue.
|
* bConfigurationValue.
|
||||||
* @return 0 on success or < 0 on error.
|
* @return 0 on success or < 0 on error.
|
||||||
*/
|
*/
|
||||||
public static native int usb_set_configuration(long dev_handle,
|
public static int usb_set_configuration(long dev_handle, int configuration) {
|
||||||
int configuration);
|
return LibusbJava1.libusb_set_configuration(dev_handle, configuration);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the active alternate setting of the current interface
|
* Sets the active alternate setting of the current interface
|
||||||
@@ -135,7 +325,26 @@ public class LibusbJava {
|
|||||||
* bAlternateSetting.
|
* bAlternateSetting.
|
||||||
* @return 0 on success or < 0 on error.
|
* @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.
|
* Clears any halt status on an endpoint.
|
||||||
@@ -146,27 +355,37 @@ public class LibusbJava {
|
|||||||
* The value specified in the descriptor field bEndpointAddress.
|
* The value specified in the descriptor field bEndpointAddress.
|
||||||
* @return 0 on success or < 0 on error.
|
* @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.<br>
|
* Resets a device by sending a RESET down the port it is connected to.<br>
|
||||||
* <br>
|
* <br>
|
||||||
* <b>Causes re-enumeration:</b> After calling <code>usb_reset</code>,
|
* <b>Causes re-enumeration:</b> After calling <code>usb_reset</code>, the
|
||||||
* the device will need to re-enumerate and thusly, requires you to find the
|
* device will need to re-enumerate and thusly, requires you to find the new
|
||||||
* new device and open a new handle. The handle used to call
|
* device and open a new handle. The handle used to call
|
||||||
* <code>usb_reset</code> will no longer work.
|
* <code>usb_reset</code> will no longer work.
|
||||||
*
|
*
|
||||||
* @param dev_handle
|
* @param dev_handle
|
||||||
* The handle to the device.
|
* The handle to the device.
|
||||||
* @return 0 on success or < 0 on error.
|
* @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.<br>
|
* Claim an interface of a device.<br>
|
||||||
* <br>
|
* <br>
|
||||||
* <b>Must be called!:</b> <code>usb_claim_interface</code> must be
|
* <b>Must be called!:</b> <code>usb_claim_interface</code> must be called
|
||||||
* called before you perform any operations related to this interface (like
|
* before you perform any operations related to this interface (like
|
||||||
* <code>usb_set_altinterface, usb_bulk_write</code>, etc).
|
* <code>usb_set_altinterface, usb_bulk_write</code>, etc).
|
||||||
*
|
*
|
||||||
* @param dev_handle
|
* @param dev_handle
|
||||||
@@ -176,7 +395,9 @@ public class LibusbJava {
|
|||||||
* bInterfaceNumber.
|
* bInterfaceNumber.
|
||||||
* @return 0 on success or < 0 on error.
|
* @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
|
* Releases a previously claimed interface
|
||||||
@@ -188,8 +409,9 @@ public class LibusbJava {
|
|||||||
* bInterfaceNumber.
|
* bInterfaceNumber.
|
||||||
* @return 0 on success or < 0 on error.
|
* @return 0 on success or < 0 on error.
|
||||||
*/
|
*/
|
||||||
public static native int usb_release_interface(long dev_handle,
|
public static int usb_release_interface(long dev_handle, int interface_) {
|
||||||
int interface_);
|
return LibusbJava1.libusb_release_interface(dev_handle, interface_);
|
||||||
|
}
|
||||||
|
|
||||||
// Control Transfers
|
// Control Transfers
|
||||||
/**
|
/**
|
||||||
@@ -207,9 +429,12 @@ public class LibusbJava {
|
|||||||
* @param timeout
|
* @param timeout
|
||||||
* @return the number of bytes written/read or < 0 on error.
|
* @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 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
|
* Retrieves the string descriptor specified by index and langid from a
|
||||||
@@ -221,8 +446,10 @@ public class LibusbJava {
|
|||||||
* @param langid
|
* @param langid
|
||||||
* @return the descriptor String or null
|
* @return the descriptor String or null
|
||||||
*/
|
*/
|
||||||
public static native String usb_get_string(long dev_handle, int index,
|
public static String usb_get_string(long dev_handle, int index, int langid) {
|
||||||
int langid);
|
|
||||||
|
return LibusbJava1.libusb_get_string_descriptor(dev_handle, (short) index, langid, 255);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <code>usb_get_string_simple</code> is a wrapper around
|
* <code>usb_get_string_simple</code> is a wrapper around
|
||||||
@@ -234,7 +461,9 @@ public class LibusbJava {
|
|||||||
* @param index
|
* @param index
|
||||||
* @return the descriptor String or null
|
* @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
|
* Retrieves a descriptor from the device identified by the type and index
|
||||||
@@ -252,8 +481,10 @@ public class LibusbJava {
|
|||||||
* resulting String)
|
* resulting String)
|
||||||
* @return the descriptor String or null
|
* @return the descriptor String or null
|
||||||
*/
|
*/
|
||||||
public static native String usb_get_descriptor(long dev_handle, byte type,
|
public static byte[] usb_get_descriptor(long dev_handle, byte type,
|
||||||
byte index, int size);
|
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
|
* Retrieves a descriptor from the device identified by the type and index
|
||||||
@@ -269,8 +500,24 @@ public class LibusbJava {
|
|||||||
* resulting String)
|
* resulting String)
|
||||||
* @return the descriptor String or null
|
* @return the descriptor String or null
|
||||||
*/
|
*/
|
||||||
public static native String usb_get_descriptor_by_endpoint(long dev_handle,
|
public static String usb_get_descriptor_by_endpoint(long dev_handle,
|
||||||
int ep, byte type, byte index, int size);
|
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
|
// Bulk Transfers
|
||||||
/**
|
/**
|
||||||
@@ -284,8 +531,11 @@ public class LibusbJava {
|
|||||||
* @param timeout
|
* @param timeout
|
||||||
* @return the number of bytes written on success or < 0 on error.
|
* @return the number of bytes written on success or < 0 on error.
|
||||||
*/
|
*/
|
||||||
public static native int usb_bulk_write(long dev_handle, int ep,
|
public static int usb_bulk_write(long dev_handle, int ep, byte[] bytes,
|
||||||
byte[] bytes, int size, int timeout);
|
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.
|
* Performs a bulk read request to the endpoint specified by ep.
|
||||||
@@ -298,8 +548,11 @@ public class LibusbJava {
|
|||||||
* @param timeout
|
* @param timeout
|
||||||
* @return the number of bytes read on success or < 0 on error.
|
* @return the number of bytes read on success or < 0 on error.
|
||||||
*/
|
*/
|
||||||
public static native int usb_bulk_read(long dev_handle, int ep,
|
public static int usb_bulk_read(long dev_handle, int ep, byte[] bytes,
|
||||||
byte[] bytes, int size, int timeout);
|
int size, int timeout) {
|
||||||
|
return LibusbJava1.libusb_bulk_transfer(dev_handle, (byte) ep, bytes,
|
||||||
|
size, timeout);
|
||||||
|
}
|
||||||
|
|
||||||
// Interrupt Transfers
|
// Interrupt Transfers
|
||||||
/**
|
/**
|
||||||
@@ -313,8 +566,11 @@ public class LibusbJava {
|
|||||||
* @param timeout
|
* @param timeout
|
||||||
* @return the number of bytes written on success or < 0 on error.
|
* @return the number of bytes written on success or < 0 on error.
|
||||||
*/
|
*/
|
||||||
public static native int usb_interrupt_write(long dev_handle, int ep,
|
public static int usb_interrupt_write(long dev_handle, int ep,
|
||||||
byte[] bytes, int size, int timeout);
|
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.
|
* Performs a interrupt read request to the endpoint specified by ep.
|
||||||
@@ -327,52 +583,19 @@ public class LibusbJava {
|
|||||||
* @param timeout
|
* @param timeout
|
||||||
* @return the number of bytes read on success or < 0 on error.
|
* @return the number of bytes read on success or < 0 on error.
|
||||||
*/
|
*/
|
||||||
public static native int usb_interrupt_read(long dev_handle, int ep,
|
public static int usb_interrupt_read(long dev_handle, int ep, byte[] bytes,
|
||||||
byte[] bytes, int size, int timeout);
|
int size, int timeout) {
|
||||||
|
return LibusbJava1.libusb_interrupt_transfer(dev_handle, (byte) ep,
|
||||||
|
bytes, size, timeout);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the error string after an error occured.
|
* Returns the error string after an error occured.
|
||||||
*
|
*
|
||||||
* @return the last error sring.
|
* @return the last error sring.
|
||||||
*/
|
*/
|
||||||
public static native String usb_strerror();
|
public static String usb_strerror() {
|
||||||
|
return LibusbJava1.libusb_strerror();
|
||||||
/** **************************************************************** */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Maps the Java error code to the system error code.<br>
|
|
||||||
* <br>
|
|
||||||
* Note that not all error codes are be mapped by this method. For more
|
|
||||||
* error codes see the file 'errno.h' on your system.<br>
|
|
||||||
* <br>
|
|
||||||
* 1: EBADF: Bad file descriptor.<br>
|
|
||||||
* 2: ENXIO: No such device or address.<br>
|
|
||||||
* 3: EBUSY: Device or resource busy.<br>
|
|
||||||
* 4: EINVAL: Invalid argument.<br>
|
|
||||||
* 5: ETIMEDOUT: Connection timed out.<br>
|
|
||||||
* 6: EIO: I/O error.<br>
|
|
||||||
* 7: ENOMEM: Not enough memory.<br>
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
1339
java/src/ch/ntb/inf/libusbJava/LibusbJava1.java
Normal file
1339
java/src/ch/ntb/inf/libusbJava/LibusbJava1.java
Normal file
File diff suppressed because it is too large
Load Diff
19
java/src/ch/ntb/inf/libusbJava/Libusb_event.java
Normal file
19
java/src/ch/ntb/inf/libusbJava/Libusb_event.java
Normal file
@@ -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");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
7
java/src/ch/ntb/inf/libusbJava/Libusb_pollfd.java
Normal file
7
java/src/ch/ntb/inf/libusbJava/Libusb_pollfd.java
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package ch.ntb.inf.libusbJava;
|
||||||
|
|
||||||
|
public class Libusb_pollfd {
|
||||||
|
int fd;
|
||||||
|
byte events;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -25,6 +25,11 @@ public class Usb_Bus {
|
|||||||
|
|
||||||
private Usb_Device root_dev;
|
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.<br>
|
* Get the first device ojects of the devices linked list.<br>
|
||||||
*
|
*
|
||||||
@@ -34,6 +39,10 @@ public class Usb_Bus {
|
|||||||
return devices;
|
return devices;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void setDevices(Usb_Device devices) {
|
||||||
|
this.devices = devices;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the systems String representation of the bus.<br>
|
* Returns the systems String representation of the bus.<br>
|
||||||
*
|
*
|
||||||
@@ -52,6 +61,10 @@ public class Usb_Bus {
|
|||||||
return next;
|
return next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void setNext(Usb_Bus bus) {
|
||||||
|
next = bus;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the previous bus object.<br>
|
* Returns the previous bus object.<br>
|
||||||
*
|
*
|
||||||
@@ -61,6 +74,10 @@ public class Usb_Bus {
|
|||||||
return prev;
|
return prev;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void setPrev(Usb_Bus bus) {
|
||||||
|
prev = bus;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the root device of this bus.<br>
|
* Get the root device of this bus.<br>
|
||||||
*
|
*
|
||||||
@@ -79,6 +96,10 @@ public class Usb_Bus {
|
|||||||
return location;
|
return location;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void setLocation(long busnumber) {
|
||||||
|
location = busnumber;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Usb_Bus " + dirname;
|
return "Usb_Bus " + dirname;
|
||||||
|
|||||||
@@ -23,7 +23,9 @@ public class Usb_Descriptor {
|
|||||||
/**
|
/**
|
||||||
* Descriptor types ({@link #bDescriptorType}).
|
* 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;
|
USB_DT_PHYSICAL = 0x23, USB_DT_HUB = 0x29;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -45,6 +45,9 @@ public class Usb_Device {
|
|||||||
public Usb_Bus getBus() {
|
public Usb_Bus getBus() {
|
||||||
return bus;
|
return bus;
|
||||||
}
|
}
|
||||||
|
protected void setBus(Usb_Bus bus){
|
||||||
|
this.bus = bus;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a reference to the first child.<br>
|
* Returns a reference to the first child.<br>
|
||||||
@@ -100,6 +103,10 @@ public class Usb_Device {
|
|||||||
return next;
|
return next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void setNext(Usb_Device dev){
|
||||||
|
next = dev;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of children of this device.<br>
|
* Returns the number of children of this device.<br>
|
||||||
*
|
*
|
||||||
@@ -117,6 +124,9 @@ public class Usb_Device {
|
|||||||
public Usb_Device getPrev() {
|
public Usb_Device getPrev() {
|
||||||
return prev;
|
return prev;
|
||||||
}
|
}
|
||||||
|
protected void setPrev(Usb_Device dev){
|
||||||
|
prev = dev;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|||||||
@@ -22,8 +22,9 @@ public class Usb_Device_Descriptor extends Usb_Descriptor {
|
|||||||
* Device and/or interface class codes.
|
* Device and/or interface class codes.
|
||||||
*/
|
*/
|
||||||
public static final int USB_CLASS_PER_INTERFACE = 0, USB_CLASS_AUDIO = 1,
|
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_COMM = 2, USB_CLASS_HID = 3, LIBUSB_CLASS_PTP = 6,
|
||||||
USB_CLASS_MASS_STORAGE = 8, USB_CLASS_HUB = 9, USB_CLASS_DATA = 10,
|
USB_CLASS_PRINTER = 7, USB_CLASS_MASS_STORAGE = 8,
|
||||||
|
USB_CLASS_HUB = 9, USB_CLASS_DATA = 10,
|
||||||
USB_CLASS_VENDOR_SPEC = 0xff;
|
USB_CLASS_VENDOR_SPEC = 0xff;
|
||||||
|
|
||||||
private short bcdUSB;
|
private short bcdUSB;
|
||||||
|
|||||||
@@ -36,14 +36,31 @@ public class Usb_Endpoint_Descriptor extends Usb_Descriptor {
|
|||||||
/**
|
/**
|
||||||
* Endpoint type mask (in bmAttributes).
|
* 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).
|
* Possible endpoint types (in bmAttributes).
|
||||||
*/
|
*/
|
||||||
public static final int USB_ENDPOINT_TYPE_CONTROL = 0,
|
public static final int USB_ENDPOINT_TRANSFER_TYPE_CONTROL = 0,
|
||||||
USB_ENDPOINT_TYPE_ISOCHRONOUS = 1, USB_ENDPOINT_TYPE_BULK = 2,
|
USB_ENDPOINT_TRANSFER_TYPE_ISOCHRONOUS = 1,
|
||||||
USB_ENDPOINT_TYPE_INTERRUPT = 3;
|
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 bEndpointAddress;
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ public class ReadWrite {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// get a device instance with vendor id and product id
|
// 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 {
|
try {
|
||||||
// data to write to the device
|
// data to write to the device
|
||||||
byte[] data = new byte[] { 0, 1, 2, 3 };
|
byte[] data = new byte[] { 0, 1, 2, 3 };
|
||||||
@@ -41,12 +41,12 @@ public class ReadWrite {
|
|||||||
// write some data to the device
|
// write some data to the device
|
||||||
// 0x03 is the endpoint address of the OUT endpoint 3 (from PC to
|
// 0x03 is the endpoint address of the OUT endpoint 3 (from PC to
|
||||||
// device)
|
// device)
|
||||||
dev.writeInterrupt(0x03, data, data.length, 2000, false);
|
dev.writeInterrupt(0x02, data, data.length, 2000, false);
|
||||||
// read some data from the device
|
// read some data from the device
|
||||||
// 0x84 is the endpoint address of the IN endpoint 4 (from PC to
|
// 0x84 is the endpoint address of the IN endpoint 4 (from PC to
|
||||||
// device)
|
// device)
|
||||||
// bit 7 (0x80) is set in case of an IN endpoint
|
// 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
|
// log the data from the device
|
||||||
logData(readData);
|
logData(readData);
|
||||||
// close the device
|
// close the device
|
||||||
|
|||||||
@@ -44,15 +44,15 @@ public class TestDevice extends AbstractDeviceInfo {
|
|||||||
@Override
|
@Override
|
||||||
public void initValues() {
|
public void initValues() {
|
||||||
setIdVendor((short) 0x8235);
|
setIdVendor((short) 0x8235);
|
||||||
setIdProduct((short) 0x0222);
|
setIdProduct((short) 0x0200);
|
||||||
setTimeout(2000);
|
setTimeout(2000);
|
||||||
setConfiguration(1);
|
setConfiguration(1);
|
||||||
setInterface(0);
|
setInterface(0);
|
||||||
setAltinterface(-1);
|
setAltinterface(-1);
|
||||||
setOutEPBulk(0x01);
|
setOutEPBulk(0x01);
|
||||||
setInEPBulk(0x82);
|
setInEPBulk(0x82);
|
||||||
setOutEPInt(0x03);
|
setOutEPInt(0x01);
|
||||||
setInEPInt(0x84);
|
setInEPInt(0x82);
|
||||||
setSleepTimeout(2000);
|
setSleepTimeout(2000);
|
||||||
setMaxDataSize(USB.FULLSPEED_MAX_BULK_PACKET_SIZE);
|
setMaxDataSize(USB.FULLSPEED_MAX_BULK_PACKET_SIZE);
|
||||||
setMode(TransferMode.Bulk);
|
setMode(TransferMode.Bulk);
|
||||||
|
|||||||
@@ -279,9 +279,7 @@ public class UsbTreeModel implements TreeModel, TreeSelectionListener {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (dev.getDescriptor().getIManufacturer() > 0) {
|
if (dev.getDescriptor().getIManufacturer() > 0) {
|
||||||
String manufacturer = LibusbJava
|
String manufacturer = LibusbJava.usb_get_string_simple(handle, devDesc.getIManufacturer());
|
||||||
.usb_get_string_simple(handle, devDesc
|
|
||||||
.getIManufacturer());
|
|
||||||
if (manufacturer == null)
|
if (manufacturer == null)
|
||||||
manufacturer = "unable to fetch manufacturer string";
|
manufacturer = "unable to fetch manufacturer string";
|
||||||
sb.append("\tiManufacturer: " + manufacturer
|
sb.append("\tiManufacturer: " + manufacturer
|
||||||
|
|||||||
@@ -306,12 +306,12 @@ public class UsbView extends JFrame {
|
|||||||
for (int i = 0; i < nofInEPs; i++) {
|
for (int i = 0; i < nofInEPs; i++) {
|
||||||
int type = inEPs[i].getBmAttributes() & 0x03;
|
int type = inEPs[i].getBmAttributes() & 0x03;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case Usb_Endpoint_Descriptor.USB_ENDPOINT_TYPE_BULK:
|
case Usb_Endpoint_Descriptor.USB_ENDPOINT_TRANSFER_TYPE_BULK:
|
||||||
testDevice.setInEPBulk(inEPs[i]
|
testDevice.setInEPBulk(inEPs[i]
|
||||||
.getBEndpointAddress() & 0xff);
|
.getBEndpointAddress() & 0xff);
|
||||||
testDevice.setInMode(TransferMode.Bulk);
|
testDevice.setInMode(TransferMode.Bulk);
|
||||||
break;
|
break;
|
||||||
case Usb_Endpoint_Descriptor.USB_ENDPOINT_TYPE_INTERRUPT:
|
case Usb_Endpoint_Descriptor.USB_ENDPOINT_TRANSFER_TYPE_INTERRUPT:
|
||||||
testDevice.setInEPInt(inEPs[i]
|
testDevice.setInEPInt(inEPs[i]
|
||||||
.getBEndpointAddress() & 0xff);
|
.getBEndpointAddress() & 0xff);
|
||||||
testDevice.setInMode(TransferMode.Interrupt);
|
testDevice.setInMode(TransferMode.Interrupt);
|
||||||
@@ -325,12 +325,12 @@ public class UsbView extends JFrame {
|
|||||||
for (int i = 0; i < nofOutEPs; i++) {
|
for (int i = 0; i < nofOutEPs; i++) {
|
||||||
int type = outEPs[i].getBmAttributes() & 0x03;
|
int type = outEPs[i].getBmAttributes() & 0x03;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case Usb_Endpoint_Descriptor.USB_ENDPOINT_TYPE_BULK:
|
case Usb_Endpoint_Descriptor.USB_ENDPOINT_TRANSFER_TYPE_BULK:
|
||||||
testDevice.setOutEPBulk(outEPs[i]
|
testDevice.setOutEPBulk(outEPs[i]
|
||||||
.getBEndpointAddress() & 0xff);
|
.getBEndpointAddress() & 0xff);
|
||||||
testDevice.setOutMode(TransferMode.Bulk);
|
testDevice.setOutMode(TransferMode.Bulk);
|
||||||
break;
|
break;
|
||||||
case Usb_Endpoint_Descriptor.USB_ENDPOINT_TYPE_INTERRUPT:
|
case Usb_Endpoint_Descriptor.USB_ENDPOINT_TRANSFER_TYPE_INTERRUPT:
|
||||||
testDevice.setOutEPInt(outEPs[i]
|
testDevice.setOutEPInt(outEPs[i]
|
||||||
.getBEndpointAddress() & 0xff);
|
.getBEndpointAddress() & 0xff);
|
||||||
testDevice.setOutMode(TransferMode.Interrupt);
|
testDevice.setOutMode(TransferMode.Interrupt);
|
||||||
|
|||||||
@@ -72,13 +72,13 @@ public class DeviceTest {
|
|||||||
testData = new byte[devinfo.getMaxDataSize()];
|
testData = new byte[devinfo.getMaxDataSize()];
|
||||||
readData = new byte[testData.length];
|
readData = new byte[testData.length];
|
||||||
// initialise the device
|
// initialise the device
|
||||||
LibusbJava.usb_set_debug(255);
|
|
||||||
dev = USB.getDevice(devinfo.getIdVendor(), devinfo.getIdProduct(),
|
dev = USB.getDevice(devinfo.getIdVendor(), devinfo.getIdProduct(),
|
||||||
devinfo.getBusName(), devinfo.getFilename());
|
devinfo.getBusName(), devinfo.getFilename());
|
||||||
assertNotNull(dev);
|
assertNotNull(dev);
|
||||||
|
|
||||||
// print the devices
|
// print the devices
|
||||||
LibusbJava.usb_init();
|
LibusbJava.usb_init();
|
||||||
|
// LibusbJava.usb_set_debug(255);
|
||||||
LibusbJava.usb_find_busses();
|
LibusbJava.usb_find_busses();
|
||||||
LibusbJava.usb_find_devices();
|
LibusbJava.usb_find_devices();
|
||||||
Usb_Bus bus = LibusbJava.usb_get_busses();
|
Usb_Bus bus = LibusbJava.usb_get_busses();
|
||||||
|
|||||||
@@ -65,13 +65,12 @@ public class MemoryLeakTest {
|
|||||||
testData = new byte[devinfo.getMaxDataSize()];
|
testData = new byte[devinfo.getMaxDataSize()];
|
||||||
readData = new byte[testData.length];
|
readData = new byte[testData.length];
|
||||||
// initialise the device
|
// initialise the device
|
||||||
LibusbJava.usb_set_debug(255);
|
|
||||||
dev = USB.getDevice(devinfo.getIdVendor(), devinfo.getIdProduct());
|
dev = USB.getDevice(devinfo.getIdVendor(), devinfo.getIdProduct());
|
||||||
assertNotNull(dev);
|
assertNotNull(dev);
|
||||||
|
|
||||||
// print the devices
|
// print the devices
|
||||||
LibusbJava.usb_init();
|
LibusbJava.usb_init();
|
||||||
LibusbJava.usb_find_busses();
|
// LibusbJava.usb_find_busses();
|
||||||
LibusbJava.usb_find_devices();
|
LibusbJava.usb_find_devices();
|
||||||
Usb_Bus bus = LibusbJava.usb_get_busses();
|
Usb_Bus bus = LibusbJava.usb_get_busses();
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
|||||||
@@ -217,10 +217,8 @@ public class TestLibUsbJava {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// used for debugging. 0 = no debugging, 255 = with debugging
|
// used for debugging. 0 = no debugging, 255 = with debugging
|
||||||
//
|
|
||||||
LibusbJava.usb_set_debug(255);
|
|
||||||
|
|
||||||
LibusbJava.usb_init();
|
LibusbJava.usb_init();
|
||||||
|
LibusbJava.usb_set_debug(255);
|
||||||
|
|
||||||
LibusbJava.usb_find_busses();
|
LibusbJava.usb_find_busses();
|
||||||
LibusbJava.usb_find_devices();
|
LibusbJava.usb_find_devices();
|
||||||
|
|||||||
@@ -15,15 +15,15 @@ public class AT90USB1287 extends AbstractDeviceInfo {
|
|||||||
@Override
|
@Override
|
||||||
public void initValues() {
|
public void initValues() {
|
||||||
setIdVendor((short) 0x8235);
|
setIdVendor((short) 0x8235);
|
||||||
setIdProduct((short) 0x0222);
|
setIdProduct((short) 0x0200);
|
||||||
setTimeout(2000);
|
setTimeout(2000);
|
||||||
setConfiguration(1);
|
setConfiguration(1);
|
||||||
setInterface(0);
|
setInterface(0);
|
||||||
setAltinterface(-1);
|
setAltinterface(-1);
|
||||||
setOutEPBulk(0x01);
|
setOutEPBulk(0x01);
|
||||||
setInEPBulk(0x82);
|
setInEPBulk(0x82);
|
||||||
setOutEPInt(0x03);
|
setOutEPInt(0x01);
|
||||||
setInEPInt(0x84);
|
setInEPInt(0x82);
|
||||||
setSleepTimeout(2000);
|
setSleepTimeout(2000);
|
||||||
setMaxDataSize(USB.FULLSPEED_MAX_BULK_PACKET_SIZE);
|
setMaxDataSize(USB.FULLSPEED_MAX_BULK_PACKET_SIZE);
|
||||||
setMode(TransferMode.Bulk);
|
setMode(TransferMode.Bulk);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#Thu Aug 24 14:28:28 CEST 2006
|
#Tue Mar 30 10:58:35 CEST 2010
|
||||||
version.major=0
|
version.major=1
|
||||||
version.minor=5
|
version.minor=0
|
||||||
version.release=9
|
version.release=0
|
||||||
|
|||||||
Reference in New Issue
Block a user