support for 64 bit os (thanks to Jonas)

dummy root bus added to UsbView
tests updated

git-svn-id: https://svn.code.sf.net/p/libusbjava/code/trunk@259 94ad28fe-ef68-46b1-9651-e7ae4fcf1c4c
This commit is contained in:
spandi
2007-09-03 19:09:49 +00:00
parent a08d70e123
commit b6d82b5754
16 changed files with 252 additions and 199 deletions

View File

@@ -542,7 +542,7 @@ JNIEXPORT jobject JNICALL Java_ch_ntb_usb_LibusbJava_usb_1get_1busses
* Method: usb_open
* Signature: (Lch/ntb/usb/Usb_Device;)I
*/
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1open
JNIEXPORT jlong JNICALL Java_ch_ntb_usb_LibusbJava_usb_1open
(JNIEnv *env, jclass obj, jobject dev)
{
clearLibusbJavaError();
@@ -558,7 +558,7 @@ JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1open
struct usb_device *device;
for (device = tmpBus->devices; device; device = device->next) {
if (device->devnum == devnum){
return (jint) usb_open(device);
return (jlong) usb_open(device);
}
}
}
@@ -572,7 +572,7 @@ JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1open
* Signature: (I)I
*/
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1close
(JNIEnv *env, jclass obj, jint dev_handle)
(JNIEnv *env, jclass obj, jlong dev_handle)
{
clearLibusbJavaError();
return (jint) usb_close((usb_dev_handle *) dev_handle);
@@ -584,7 +584,7 @@ JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1close
* Signature: (II)I
*/
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1set_1configuration
(JNIEnv *env, jclass obj, jint dev_handle, jint configuration)
(JNIEnv *env, jclass obj, jlong dev_handle, jint configuration)
{
clearLibusbJavaError();
return usb_set_configuration((usb_dev_handle *) dev_handle, configuration);
@@ -596,7 +596,7 @@ JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1set_1configuration
* Signature: (II)I
*/
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1set_1altinterface
(JNIEnv *env, jclass obj, jint dev_handle, jint alternate)
(JNIEnv *env, jclass obj, jlong dev_handle, jint alternate)
{
clearLibusbJavaError();
return usb_set_altinterface((usb_dev_handle *) dev_handle, alternate);
@@ -608,7 +608,7 @@ JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1set_1altinterface
* Signature: (II)I
*/
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1clear_1halt
(JNIEnv *env, jclass obj, jint dev_handle, jint ep)
(JNIEnv *env, jclass obj, jlong dev_handle, jint ep)
{
clearLibusbJavaError();
return usb_clear_halt((usb_dev_handle *) dev_handle, (unsigned) ep);
@@ -620,7 +620,7 @@ JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1clear_1halt
* Signature: (I)I
*/
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1reset
(JNIEnv *env, jclass obj, jint dev_handle)
(JNIEnv *env, jclass obj, jlong dev_handle)
{
clearLibusbJavaError();
return usb_reset((usb_dev_handle *) dev_handle);
@@ -632,7 +632,7 @@ JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1reset
* Signature: (II)I
*/
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1claim_1interface
(JNIEnv *env, jclass obj, jint dev_handle, jint interface)
(JNIEnv *env, jclass obj, jlong dev_handle, jint interface)
{
clearLibusbJavaError();
return usb_claim_interface((usb_dev_handle *) dev_handle, interface);
@@ -644,7 +644,7 @@ JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1claim_1interface
* Signature: (II)I
*/
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1release_1interface
(JNIEnv *env, jclass obj, jint dev_handle, jint interface)
(JNIEnv *env, jclass obj, jlong dev_handle, jint interface)
{
clearLibusbJavaError();
return usb_release_interface((usb_dev_handle *) dev_handle, interface);
@@ -656,7 +656,7 @@ JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1release_1interface
* Signature: (IIIII[BII)I
*/
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1control_1msg
(JNIEnv *env, jclass obj, jint dev_handle, jint requesttype, jint request, jint value, jint index, jbyteArray jbytes, jint size, jint timeout)
(JNIEnv *env, jclass obj, jlong dev_handle, jint requesttype, jint request, jint value, jint index, jbyteArray jbytes, jint size, jint timeout)
{
clearLibusbJavaError();
jbyte *bytes = env->GetByteArrayElements(jbytes, NULL);
@@ -671,7 +671,7 @@ JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1control_1msg
* Signature: (III)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_ch_ntb_usb_LibusbJava_usb_1get_1string
(JNIEnv *env, jclass obj, jint dev_handle, jint index, jint langid)
(JNIEnv *env, jclass obj, jlong dev_handle, jint index, jint langid)
{
clearLibusbJavaError();
char string[256];
@@ -687,7 +687,7 @@ JNIEXPORT jstring JNICALL Java_ch_ntb_usb_LibusbJava_usb_1get_1string
* Signature: (II)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_ch_ntb_usb_LibusbJava_usb_1get_1string_1simple
(JNIEnv *env, jclass obj, jint dev_handle, jint index)
(JNIEnv *env, jclass obj, jlong dev_handle, jint index)
{
clearLibusbJavaError();
char string[256];
@@ -703,7 +703,7 @@ JNIEXPORT jstring JNICALL Java_ch_ntb_usb_LibusbJava_usb_1get_1string_1simple
* Signature: (IBBI)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_ch_ntb_usb_LibusbJava_usb_1get_1descriptor
(JNIEnv *env, jclass obj, jint dev_handle, jbyte type, jbyte index, jint size)
(JNIEnv *env, jclass obj, jlong dev_handle, jbyte type, jbyte index, jint size)
{
clearLibusbJavaError();
char *string = (char *) malloc(size * sizeof(char));
@@ -720,7 +720,7 @@ JNIEXPORT jstring JNICALL Java_ch_ntb_usb_LibusbJava_usb_1get_1descriptor
* Signature: (IIBBI)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_ch_ntb_usb_LibusbJava_usb_1get_1descriptor_1by_1endpoint
(JNIEnv *env, jclass obj, jint dev_handle, jint ep, jbyte type, jbyte index, jint size)
(JNIEnv *env, jclass obj, jlong dev_handle, jint ep, jbyte type, jbyte index, jint size)
{
clearLibusbJavaError();
char *string = (char *) malloc(size * sizeof(char));
@@ -737,7 +737,7 @@ JNIEXPORT jstring JNICALL Java_ch_ntb_usb_LibusbJava_usb_1get_1descriptor_1by_1e
* Signature: (II[BII)I
*/
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1bulk_1write
(JNIEnv *env, jclass obj, jint dev_handle, jint ep, jbyteArray jbytes, jint size, jint timeout)
(JNIEnv *env, jclass obj, jlong dev_handle, jint ep, jbyteArray jbytes, jint size, jint timeout)
{
clearLibusbJavaError();
jbyte *bytes = env->GetByteArrayElements(jbytes, NULL);
@@ -750,7 +750,7 @@ JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1bulk_1write
* Signature: (II[BII)I
*/
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1bulk_1read
(JNIEnv *env, jclass obj, jint dev_handle, jint ep, jbyteArray jbytes, jint size, jint timeout)
(JNIEnv *env, jclass obj, jlong dev_handle, jint ep, jbyteArray jbytes, jint size, jint timeout)
{
clearLibusbJavaError();
char *bytes = (char *) malloc(size * sizeof(char));
@@ -767,7 +767,7 @@ JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1bulk_1read
* Signature: (II[BII)I
*/
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1interrupt_1write
(JNIEnv *env, jclass obj, jint dev_handle, jint ep, jbyteArray jbytes, jint size, jint timeout)
(JNIEnv *env, jclass obj, jlong dev_handle, jint ep, jbyteArray jbytes, jint size, jint timeout)
{
clearLibusbJavaError();
jbyte *bytes = env->GetByteArrayElements(jbytes, NULL);
@@ -780,7 +780,7 @@ JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1interrupt_1write
* Signature: (II[BII)I
*/
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1interrupt_1read
(JNIEnv *env, jclass obj, jint dev_handle, jint ep, jbyteArray jbytes, jint size, jint timeout)
(JNIEnv *env, jclass obj, jlong dev_handle, jint ep, jbyteArray jbytes, jint size, jint timeout)
{
clearLibusbJavaError();
char *bytes = (char *) malloc(size * sizeof(char));

View File

@@ -50,138 +50,138 @@ JNIEXPORT jobject JNICALL Java_ch_ntb_usb_LibusbJava_usb_1get_1busses
/*
* Class: ch_ntb_usb_LibusbJava
* Method: usb_open
* Signature: (Lch/ntb/usb/Usb_Device;)I
* Signature: (Lch/ntb/usb/Usb_Device;)J
*/
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1open
JNIEXPORT jlong JNICALL Java_ch_ntb_usb_LibusbJava_usb_1open
(JNIEnv *, jclass, jobject);
/*
* Class: ch_ntb_usb_LibusbJava
* Method: usb_close
* Signature: (I)I
* Signature: (J)I
*/
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1close
(JNIEnv *, jclass, jint);
(JNIEnv *, jclass, jlong);
/*
* Class: ch_ntb_usb_LibusbJava
* Method: usb_set_configuration
* Signature: (II)I
* Signature: (JI)I
*/
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1set_1configuration
(JNIEnv *, jclass, jint, jint);
(JNIEnv *, jclass, jlong, jint);
/*
* Class: ch_ntb_usb_LibusbJava
* Method: usb_set_altinterface
* Signature: (II)I
* Signature: (JI)I
*/
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1set_1altinterface
(JNIEnv *, jclass, jint, jint);
(JNIEnv *, jclass, jlong, jint);
/*
* Class: ch_ntb_usb_LibusbJava
* Method: usb_clear_halt
* Signature: (II)I
* Signature: (JI)I
*/
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1clear_1halt
(JNIEnv *, jclass, jint, jint);
(JNIEnv *, jclass, jlong, jint);
/*
* Class: ch_ntb_usb_LibusbJava
* Method: usb_reset
* Signature: (I)I
* Signature: (J)I
*/
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1reset
(JNIEnv *, jclass, jint);
(JNIEnv *, jclass, jlong);
/*
* Class: ch_ntb_usb_LibusbJava
* Method: usb_claim_interface
* Signature: (II)I
* Signature: (JI)I
*/
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1claim_1interface
(JNIEnv *, jclass, jint, jint);
(JNIEnv *, jclass, jlong, jint);
/*
* Class: ch_ntb_usb_LibusbJava
* Method: usb_release_interface
* Signature: (II)I
* Signature: (JI)I
*/
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1release_1interface
(JNIEnv *, jclass, jint, jint);
(JNIEnv *, jclass, jlong, jint);
/*
* Class: ch_ntb_usb_LibusbJava
* Method: usb_control_msg
* Signature: (IIIII[BII)I
* Signature: (JIIII[BII)I
*/
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1control_1msg
(JNIEnv *, jclass, jint, jint, jint, jint, jint, jbyteArray, jint, jint);
(JNIEnv *, jclass, jlong, jint, jint, jint, jint, jbyteArray, jint, jint);
/*
* Class: ch_ntb_usb_LibusbJava
* Method: usb_get_string
* Signature: (III)Ljava/lang/String;
* Signature: (JII)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_ch_ntb_usb_LibusbJava_usb_1get_1string
(JNIEnv *, jclass, jint, jint, jint);
(JNIEnv *, jclass, jlong, jint, jint);
/*
* Class: ch_ntb_usb_LibusbJava
* Method: usb_get_string_simple
* Signature: (II)Ljava/lang/String;
* Signature: (JI)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_ch_ntb_usb_LibusbJava_usb_1get_1string_1simple
(JNIEnv *, jclass, jint, jint);
(JNIEnv *, jclass, jlong, jint);
/*
* Class: ch_ntb_usb_LibusbJava
* Method: usb_get_descriptor
* Signature: (IBBI)Ljava/lang/String;
* Signature: (JBBI)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_ch_ntb_usb_LibusbJava_usb_1get_1descriptor
(JNIEnv *, jclass, jint, jbyte, jbyte, jint);
(JNIEnv *, jclass, jlong, jbyte, jbyte, jint);
/*
* Class: ch_ntb_usb_LibusbJava
* Method: usb_get_descriptor_by_endpoint
* Signature: (IIBBI)Ljava/lang/String;
* Signature: (JIBBI)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_ch_ntb_usb_LibusbJava_usb_1get_1descriptor_1by_1endpoint
(JNIEnv *, jclass, jint, jint, jbyte, jbyte, jint);
(JNIEnv *, jclass, jlong, jint, jbyte, jbyte, jint);
/*
* Class: ch_ntb_usb_LibusbJava
* Method: usb_bulk_write
* Signature: (II[BII)I
* Signature: (JI[BII)I
*/
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1bulk_1write
(JNIEnv *, jclass, jint, jint, jbyteArray, jint, jint);
(JNIEnv *, jclass, jlong, jint, jbyteArray, jint, jint);
/*
* Class: ch_ntb_usb_LibusbJava
* Method: usb_bulk_read
* Signature: (II[BII)I
* Signature: (JI[BII)I
*/
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1bulk_1read
(JNIEnv *, jclass, jint, jint, jbyteArray, jint, jint);
(JNIEnv *, jclass, jlong, jint, jbyteArray, jint, jint);
/*
* Class: ch_ntb_usb_LibusbJava
* Method: usb_interrupt_write
* Signature: (II[BII)I
* Signature: (JI[BII)I
*/
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1interrupt_1write
(JNIEnv *, jclass, jint, jint, jbyteArray, jint, jint);
(JNIEnv *, jclass, jlong, jint, jbyteArray, jint, jint);
/*
* Class: ch_ntb_usb_LibusbJava
* Method: usb_interrupt_read
* Signature: (II[BII)I
* Signature: (JI[BII)I
*/
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1interrupt_1read
(JNIEnv *, jclass, jint, jint, jbyteArray, jint, jint);
(JNIEnv *, jclass, jlong, jint, jbyteArray, jint, jint);
/*
* Class: ch_ntb_usb_LibusbJava

View File

@@ -16,7 +16,7 @@
<property file="project.properties" />
<property file="version.properties" />
<property name="version.win.rc" value="${version.major},${version.minor},${version.micro},${version.nano}" />
<property name="version.win.rc" value="${version.major},${version.minor},${version.micro},${version.nano}" />
<property name="version.win.str" value="${version.major}.${version.minor}.${version.micro}.${version.nano}" />
<property name="version.linux" value="${version.major}.${version.minor}.${version.micro}" />
@@ -63,20 +63,20 @@
<arg value="${build.win.resource.obj}" />
<arg value="${build.lib.libusb}" />
</exec>
</target>
</target>
<target name="linux" depends="clean" description="--> Build ${build.shlib.linux.shlibname}">
<exec dir="." executable="${build.linux.compiler}">
<arg value="-shared" />
<arg value="-fPIC" />
<arg value="-Wl,-soname,${build.shlib.linux.shlibname}" />
<arg value="-I${build.linux.includes}" />
<arg value="-I${build.linux.includes2}" />
<arg value="-I${build.linux.includes3}" />
<arg value="-shared" />
<arg value="${build.shlib.srcname}" />
<arg value="${build.shlib.srcname}" />
<arg value="-o${build.shlib.linux.shlibname}.${version.linux}" />
<arg value="${build.linux.includes}/${build.lib.libusb}" />
<arg value="${build.linux.includes}/${build.lib.libusbpp}" />
<arg value="${build.linux.includes}/${build.linux.lib.libusb}" />
<arg value="${build.linux.includes}/${build.linux.lib.libusbpp}" />
</exec>
</target>

View File

@@ -8,6 +8,8 @@ build.dir.bin=bin
# filenames
build.lib.libusb=libusb.a
build.lib.libusbpp=libusbpp.a
build.linux.lib.libusb=libusb.so
build.linux.lib.libusbpp=libusbpp.so
build.mac.lib.libusb=libusb.dylib
build.mac.lib.libusbpp=libusbpp.dylib
build.shlib.srcname=LibusbJava.cpp

View File

@@ -2,6 +2,6 @@
#define RC_FILE_SUB_TYPE VFT2_UNKNOWN
#define RC_PRODUCT_STR "Java LibUsb-Win32 wrapper - DLL"
#define RC_FILE_NAME_STR "LibusbJava.dll"
#define RC_VERSION_STR "0.2.1.0"
#define RC_VERSION_STR "0.2.2.0"
#include "common.rc"

View File

@@ -1,5 +1,5 @@
# NOTE: if the version is changed -> change the define in resource.rc"
# NOTE: if the version is changed -> change the define in resource.rc
version.major=0
version.minor=2
version.micro=1
version.micro=2
version.nano=0

View File

@@ -32,7 +32,7 @@
<target name="compile" depends="clean" description="--> Compile Java files">
<mkdir dir="${project.dir.bin}" />
<javac srcdir="${project.dir.src}" destdir="${project.dir.bin}" debug="on" />
<javac srcdir="${project.dir.src}" destdir="${project.dir.bin}" debug="on" encoding="iso-8859-1"/>
</target>
<target name="jar" depends="compile" description="--> Create Jar">
@@ -60,7 +60,7 @@
</target>
<target name="javadoc" description="--> Create Javadoc">
<javadoc destdir="${project.dir.doc}">
<javadoc destdir="${project.dir.doc}" encoding="iso-8859-1">
<fileset dir="${project.dir.src}" defaultexcludes="yes" />
</javadoc>
</target>

View File

@@ -27,7 +27,7 @@ public class Device {
private int idVendor, idProduct, dev_configuration, dev_interface,
dev_altinterface;
private int usbDevHandle;
private long usbDevHandle;
private boolean resetOnFirstOpen, resetDone;
@@ -181,7 +181,7 @@ public class Device {
dev = initDevice();
if (dev != null) {
int res = LibusbJava.usb_open(dev);
long res = LibusbJava.usb_open(dev);
if (res == 0) {
throw new USBException("LibusbJava.usb_open: "
+ LibusbJava.usb_strerror());
@@ -411,16 +411,17 @@ public class Device {
return writeInterrupt(out_ep_address, data, size, timeout,
false);
}
throw new USBTimeoutException("LibusbJava.usb_bulk_write: "
+ LibusbJava.usb_strerror());
throw new USBTimeoutException(
"LibusbJava.usb_interrupt_write: "
+ LibusbJava.usb_strerror());
}
throw new USBException("LibusbJava.usb_bulk_write: "
throw new USBException("LibusbJava.usb_interrupt_write: "
+ LibusbJava.usb_strerror());
}
logger.info("length written: " + lenWritten);
if (logger.isLoggable(Level.FINEST)) {
StringBuffer sb = new StringBuffer("bulkwrite, ep 0x"
StringBuffer sb = new StringBuffer("interruptwrite, ep 0x"
+ Integer.toHexString(out_ep_address) + ": " + lenWritten
+ " Bytes sent: ");
for (int i = 0; i < lenWritten; i++) {
@@ -472,16 +473,16 @@ public class Device {
return readInterrupt(in_ep_address, data, size, timeout,
false);
}
throw new USBTimeoutException("LibusbJava.usb_bulk_read: "
throw new USBTimeoutException("LibusbJava.usb_interrupt_read: "
+ LibusbJava.usb_strerror());
}
throw new USBException("LibusbJava.usb_bulk_read: "
throw new USBException("LibusbJava.usb_interrupt_read: "
+ LibusbJava.usb_strerror());
}
logger.info("length read: " + lenRead);
if (logger.isLoggable(Level.FINEST)) {
StringBuffer sb = new StringBuffer("bulkread, ep 0x"
StringBuffer sb = new StringBuffer("interrupt, ep 0x"
+ Integer.toHexString(in_ep_address) + ": " + lenRead
+ " Bytes received: ");
for (int i = 0; i < lenRead; i++) {
@@ -582,7 +583,7 @@ public class Device {
* @throws USBException
* throws an USBException if the action fails
*/
private void claim_interface(int usb_dev_handle, int configuration,
private void claim_interface(long usb_dev_handle, int configuration,
int interface_, int altinterface) throws USBException {
if (LibusbJava.usb_set_configuration(usb_dev_handle, configuration) < 0) {
usbDevHandle = 0;
@@ -619,7 +620,7 @@ public class Device {
* @throws USBException
* throws an USBException if the action fails
*/
private void release_interface(int dev_handle, int interface_)
private void release_interface(long dev_handle, int interface_)
throws USBException {
if (LibusbJava.usb_release_interface(dev_handle, interface_) < 0) {
usbDevHandle = 0;

View File

@@ -102,7 +102,7 @@ public class LibusbJava {
* @return a handle used in future communication with the device. 0 if an
* error has occurred.
*/
public static native int usb_open(Usb_Device dev);
public static native long usb_open(Usb_Device dev);
/**
* <code>usb_close</code> closes a device opened with
@@ -112,7 +112,7 @@ public class LibusbJava {
* The handle to the device.
* @return 0 on success or < 0 on error.
*/
public static native int usb_close(int dev_handle);
public static native int usb_close(long dev_handle);
/**
* Sets the active configuration of a device
@@ -124,7 +124,7 @@ public class LibusbJava {
* bConfigurationValue.
* @return 0 on success or < 0 on error.
*/
public static native int usb_set_configuration(int dev_handle,
public static native int usb_set_configuration(long dev_handle,
int configuration);
/**
@@ -137,7 +137,7 @@ public class LibusbJava {
* bAlternateSetting.
* @return 0 on success or < 0 on error.
*/
public static native int usb_set_altinterface(int dev_handle, int alternate);
public static native int usb_set_altinterface(long dev_handle, int alternate);
/**
* Clears any halt status on an endpoint.
@@ -148,7 +148,7 @@ 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(int dev_handle, int ep);
public static native int usb_clear_halt(long dev_handle, int ep);
/**
* Resets a device by sending a RESET down the port it is connected to.<br>
@@ -162,7 +162,7 @@ public class LibusbJava {
* The handle to the device.
* @return 0 on success or < 0 on error.
*/
public static native int usb_reset(int dev_handle);
public static native int usb_reset(long dev_handle);
/**
* Claim an interface of a device.<br>
@@ -178,7 +178,7 @@ public class LibusbJava {
* bInterfaceNumber.
* @return 0 on success or < 0 on error.
*/
public static native int usb_claim_interface(int dev_handle, int interface_);
public static native int usb_claim_interface(long dev_handle, int interface_);
/**
* Releases a previously claimed interface
@@ -190,7 +190,7 @@ public class LibusbJava {
* bInterfaceNumber.
* @return 0 on success or < 0 on error.
*/
public static native int usb_release_interface(int dev_handle,
public static native int usb_release_interface(long dev_handle,
int interface_);
// Control Transfers
@@ -209,7 +209,7 @@ public class LibusbJava {
* @param timeout
* @return the number of bytes written/read or < 0 on error.
*/
public static native int usb_control_msg(int dev_handle, int requesttype,
public static native int usb_control_msg(long dev_handle, int requesttype,
int request, int value, int index, byte[] bytes, int size,
int timeout);
@@ -223,7 +223,7 @@ public class LibusbJava {
* @param langid
* @return the descriptor String or null
*/
public static native String usb_get_string(int dev_handle, int index,
public static native String usb_get_string(long dev_handle, int index,
int langid);
/**
@@ -236,13 +236,13 @@ public class LibusbJava {
* @param index
* @return the descriptor String or null
*/
public static native String usb_get_string_simple(int dev_handle, int index);
public static native String usb_get_string_simple(long dev_handle, int index);
/**
* Retrieves a descriptor from the device identified by the type and index
* of the descriptor from the default control pipe.<br>
* <br>
* See {@link #usb_get_descriptor_by_endpoint(int, int, byte, byte, int)}
* See {@link #usb_get_descriptor_by_endpoint(long, int, byte, byte, int)}
* for a function that allows the control endpoint to be specified.
*
* @param dev_handle
@@ -254,7 +254,7 @@ public class LibusbJava {
* resulting String)
* @return the descriptor String or null
*/
public static native String usb_get_descriptor(int dev_handle, byte type,
public static native String usb_get_descriptor(long dev_handle, byte type,
byte index, int size);
/**
@@ -271,7 +271,7 @@ public class LibusbJava {
* resulting String)
* @return the descriptor String or null
*/
public static native String usb_get_descriptor_by_endpoint(int dev_handle,
public static native String usb_get_descriptor_by_endpoint(long dev_handle,
int ep, byte type, byte index, int size);
// Bulk Transfers
@@ -286,7 +286,7 @@ public class LibusbJava {
* @param timeout
* @return the number of bytes written on success or < 0 on error.
*/
public static native int usb_bulk_write(int dev_handle, int ep,
public static native int usb_bulk_write(long dev_handle, int ep,
byte[] bytes, int size, int timeout);
/**
@@ -300,7 +300,7 @@ public class LibusbJava {
* @param timeout
* @return the number of bytes read on success or < 0 on error.
*/
public static native int usb_bulk_read(int dev_handle, int ep,
public static native int usb_bulk_read(long dev_handle, int ep,
byte[] bytes, int size, int timeout);
// Interrupt Transfers
@@ -315,7 +315,7 @@ public class LibusbJava {
* @param timeout
* @return the number of bytes written on success or < 0 on error.
*/
public static native int usb_interrupt_write(int dev_handle, int ep,
public static native int usb_interrupt_write(long dev_handle, int ep,
byte[] bytes, int size, int timeout);
/**
@@ -329,7 +329,7 @@ public class LibusbJava {
* @param timeout
* @return the number of bytes read on success or < 0 on error.
*/
public static native int usb_interrupt_read(int dev_handle, int ep,
public static native int usb_interrupt_read(long dev_handle, int ep,
byte[] bytes, int size, int timeout);
/**

View File

@@ -44,7 +44,7 @@ public class Usb_Config_Descriptor extends Usb_Descriptor {
private int extralen;
/**
* Returns the value to use as an argument to select this configuration ({@link LibusbJava#usb_set_configuration(int, int)}).
* Returns the value to use as an argument to select this configuration ({@link LibusbJava#usb_set_configuration(long, int)}).
*
* @return the value to use as an argument to select this configuration
*/

View File

@@ -53,7 +53,7 @@ public class Usb_Interface_Descriptor extends Usb_Descriptor {
}
/**
* Returns the value used to select the alternate setting ({@link LibusbJava#usb_set_altinterface(int, int)}).<br>
* Returns the value used to select the alternate setting ({@link LibusbJava#usb_set_altinterface(long, int)}).<br>
*
* @return the alternate setting
*/

View File

@@ -31,6 +31,8 @@ public class UsbTreeModel implements TreeModel, TreeSelectionListener {
private Usb_Bus rootBus;
private static final String USB_ROOT = "USB";
private JTextArea textArea;
private Vector<TreeModelListener> treeModelListeners = new Vector<TreeModelListener>();
@@ -52,14 +54,26 @@ public class UsbTreeModel implements TreeModel, TreeSelectionListener {
* Returns the root of the tree.
*/
public Object getRoot() {
return rootBus;
return USB_ROOT;
}
/**
* Returns the child of parent at index index in the parent's child array.
*/
public Object getChild(Object parent, int index) {
if (parent instanceof Usb_Bus) {
if (parent instanceof String && ((String) parent).compareTo(USB_ROOT) == 0)
{
Usb_Bus curBus = rootBus;
for (int i = 0; curBus != null; curBus = curBus.getNext(), i++)
{
if (i == index)
return curBus;
}
}
else if (parent instanceof Usb_Bus) {
Usb_Device device = ((Usb_Bus) parent).getDevices();
int count = 0;
while (device != null) {
@@ -104,8 +118,23 @@ public class UsbTreeModel implements TreeModel, TreeSelectionListener {
/**
* Returns the number of children of parent.
*/
public int getChildCount(Object parent) {
if (parent instanceof Usb_Bus) {
public int getChildCount(Object parent)
{
if (parent instanceof String && ((String) parent).compareTo(USB_ROOT) == 0)
{
int count = 0;
Usb_Bus curBus = rootBus;
for (; curBus != null; curBus = curBus.getNext())
{
count++;
}
return count;
}
else if (parent instanceof Usb_Bus) {
Usb_Device device = ((Usb_Bus) parent).getDevices();
int count = 0;
while (device != null) {
@@ -243,7 +272,7 @@ public class UsbTreeModel implements TreeModel, TreeSelectionListener {
|| (dev.getDescriptor().getIProduct() > 0) || (dev
.getDescriptor().getISerialNumber() > 0))) {
if (tmpDevDesc.equals(devDesc)) {
int handle = LibusbJava.usb_open(dev);
long handle = LibusbJava.usb_open(dev);
sb.append("\nString descriptors\n");
if (handle <= 0) {
sb.append("\terror opening the device\n");
@@ -319,7 +348,7 @@ public class UsbTreeModel implements TreeModel, TreeSelectionListener {
for (int i = 0; i < tmpConfDesc.length; i++) {
if ((tmpConfDesc.equals(confDesc))
&& (confDesc.getIConfiguration() > 0)) {
int handle = LibusbJava.usb_open(dev);
long handle = LibusbJava.usb_open(dev);
sb.append("\nString descriptors\n");
if (handle <= 0) {
sb.append("\terror opening the device\n");
@@ -395,9 +424,9 @@ public class UsbTreeModel implements TreeModel, TreeSelectionListener {
Usb_Interface_Descriptor[] tmpIntDescs = ints[j]
.getAltsetting();
for (int k = 0; k < ints.length; k++) {
if (tmpIntDescs[i].equals(intDesc)
if (i < tmpIntDescs.length && tmpIntDescs[i].equals(intDesc)
&& (intDesc.getIInterface() > 0)) {
int handle = LibusbJava.usb_open(dev);
long handle = LibusbJava.usb_open(dev);
sb.append("\nString descriptors\n");
if (handle <= 0) {
sb

View File

@@ -174,9 +174,7 @@ public class DeviceTest {
devinfo.setMode(TransferMode.Bulk);
doOpen();
for (int i = 0; i < NumberOfIterations; i++) {
initTestData();
doWriteRead();
compare(testData, readData);
}
doClose();
}
@@ -225,80 +223,99 @@ public class DeviceTest {
@Test
public void controlMsg() throws Exception {
dev.open(devinfo.getConfiguration(), devinfo.getInterface(), devinfo
.getAltinterface());
// GET STATUS (device)
byte[] data = getTestData(2);
int length = dev.controlMsg(USB.REQ_TYPE_DIR_DEVICE_TO_HOST
| USB.REQ_TYPE_TYPE_STANDARD | USB.REQ_TYPE_RECIP_DEVICE,
USB.REQ_GET_STATUS, 0, 0, data, data.length, devinfo
.getTimeout(), false);
assertEquals((byte) 0x01, data[0]);
assertEquals((byte) 0x00, data[1]);
// GET STATUS (interface)
data = getTestData(2);
length = dev.controlMsg(USB.REQ_TYPE_DIR_DEVICE_TO_HOST
| USB.REQ_TYPE_TYPE_STANDARD | USB.REQ_TYPE_RECIP_INTERFACE,
USB.REQ_GET_STATUS, 0, 0, data, data.length, devinfo
.getTimeout(), false);
assertEquals((byte) 0x00, data[0]);
assertEquals((byte) 0x00, data[1]);
// GET STATUS (endpoint)
data = getTestData(2);
length = dev.controlMsg(USB.REQ_TYPE_DIR_DEVICE_TO_HOST
| USB.REQ_TYPE_TYPE_STANDARD | USB.REQ_TYPE_RECIP_ENDPOINT,
USB.REQ_GET_STATUS, 0, 0, data, data.length, devinfo
.getTimeout(), false);
assertEquals((byte) 0x00, data[0]);
assertEquals((byte) 0x00, data[1]);
// GET CONFIGURATION
data = getTestData(1);
length = dev.controlMsg(USB.REQ_TYPE_DIR_DEVICE_TO_HOST
| USB.REQ_TYPE_TYPE_STANDARD | USB.REQ_TYPE_RECIP_DEVICE,
USB.REQ_GET_CONFIGURATION, 0, 0, data, data.length, devinfo
.getTimeout(), false);
assertEquals((byte) devinfo.getConfiguration(), data[0]);
// // GET INTERFACE
// data = byte[1];
// length = dev.controlMsg(USB.REQ_TYPE_DIR_DEVICE_TO_HOST
// | USB.REQ_TYPE_TYPE_STANDARD | USB.REQ_TYPE_RECIP_INTERFACE,
// USB.REQ_GET_INTERFACE, 0, devinfo.getInterface(), data, data.length,
// devinfo
// .getTimeout(), false);
// logData(data, length);
// GET DESCRIPTOR (device descriptor)
data = getTestData(128);
length = dev.controlMsg(USB.REQ_TYPE_DIR_DEVICE_TO_HOST
| USB.REQ_TYPE_TYPE_STANDARD | USB.REQ_TYPE_RECIP_DEVICE,
USB.REQ_GET_DESCRIPTOR, 1 << 8, 0, data, data.length, devinfo
.getTimeout(), false);
validateDeviceDescriptor(data, length);
// GET DESCRIPTOR (string descriptor (1))
data = getTestData(128);
length = dev.controlMsg(USB.REQ_TYPE_DIR_DEVICE_TO_HOST
| USB.REQ_TYPE_TYPE_STANDARD | USB.REQ_TYPE_RECIP_DEVICE,
USB.REQ_GET_DESCRIPTOR, (3 << 8) + 1, 0, data, data.length,
devinfo.getTimeout(), false);
String s = getString(data, length);
assertEquals(s, Manufacturer);
// GET DESCRIPTOR (string descriptor (2))
data = getTestData(128);
length = dev.controlMsg(USB.REQ_TYPE_DIR_DEVICE_TO_HOST
| USB.REQ_TYPE_TYPE_STANDARD | USB.REQ_TYPE_RECIP_DEVICE,
USB.REQ_GET_DESCRIPTOR, (3 << 8) + 2, 0, data, data.length,
devinfo.getTimeout(), false);
s = getString(data, length);
assertEquals(s, Product);
// GET DESCRIPTOR (string descriptor (3))
data = getTestData(128);
length = dev.controlMsg(USB.REQ_TYPE_DIR_DEVICE_TO_HOST
| USB.REQ_TYPE_TYPE_STANDARD | USB.REQ_TYPE_RECIP_DEVICE,
USB.REQ_GET_DESCRIPTOR, (3 << 8) + 3, 0, data, data.length,
devinfo.getTimeout(), false);
s = getString(data, length);
assertEquals(s, SerialVersion);
// close the device
dev.close();
try {
dev.open(devinfo.getConfiguration(), devinfo.getInterface(), devinfo
.getAltinterface());
// GET STATUS (device)
byte[] data = getTestData(2);
int length = dev.controlMsg(USB.REQ_TYPE_DIR_DEVICE_TO_HOST
| USB.REQ_TYPE_TYPE_STANDARD | USB.REQ_TYPE_RECIP_DEVICE,
USB.REQ_GET_STATUS, 0, 0, data, data.length, devinfo
.getTimeout(), false);
assertTrue(length > 0);
assertEquals((byte) 0x01, data[0]);
assertEquals((byte) 0x00, data[1]);
// GET STATUS (interface)
data = getTestData(2);
length = dev.controlMsg(USB.REQ_TYPE_DIR_DEVICE_TO_HOST
| USB.REQ_TYPE_TYPE_STANDARD | USB.REQ_TYPE_RECIP_INTERFACE,
USB.REQ_GET_STATUS, 0, 0, data, data.length, devinfo
.getTimeout(), false);
assertTrue(length > 0);
assertEquals((byte) 0x00, data[0]);
assertEquals((byte) 0x00, data[1]);
// GET STATUS (endpoint)
data = getTestData(2);
length = dev.controlMsg(USB.REQ_TYPE_DIR_DEVICE_TO_HOST
| USB.REQ_TYPE_TYPE_STANDARD | USB.REQ_TYPE_RECIP_ENDPOINT,
USB.REQ_GET_STATUS, 0, 0, data, data.length, devinfo
.getTimeout(), false);
assertTrue(length > 0);
assertEquals((byte) 0x00, data[0]);
assertEquals((byte) 0x00, data[1]);
// GET CONFIGURATION
data = getTestData(1);
length = dev.controlMsg(USB.REQ_TYPE_DIR_DEVICE_TO_HOST
| USB.REQ_TYPE_TYPE_STANDARD | USB.REQ_TYPE_RECIP_DEVICE,
USB.REQ_GET_CONFIGURATION, 0, 0, data, data.length, devinfo
.getTimeout(), false);
assertTrue(length > 0);
assertEquals((byte) devinfo.getConfiguration(), data[0]);
// // GET INTERFACE
// data = byte[1];
// length = dev.controlMsg(USB.REQ_TYPE_DIR_DEVICE_TO_HOST
// | USB.REQ_TYPE_TYPE_STANDARD | USB.REQ_TYPE_RECIP_INTERFACE,
// USB.REQ_GET_INTERFACE, 0, devinfo.getInterface(), data, data.length,
// devinfo
// .getTimeout(), false);
// logData(data, length);
// GET DESCRIPTOR (device descriptor)
data = getTestData(128);
length = dev.controlMsg(USB.REQ_TYPE_DIR_DEVICE_TO_HOST
| USB.REQ_TYPE_TYPE_STANDARD | USB.REQ_TYPE_RECIP_DEVICE,
USB.REQ_GET_DESCRIPTOR, 1 << 8, 0, data, data.length, devinfo
.getTimeout(), false);
validateDeviceDescriptor(data, length);
// GET DESCRIPTOR (string descriptor (1))
data = getTestData(128);
length = dev.controlMsg(USB.REQ_TYPE_DIR_DEVICE_TO_HOST
| USB.REQ_TYPE_TYPE_STANDARD | USB.REQ_TYPE_RECIP_DEVICE,
USB.REQ_GET_DESCRIPTOR, (3 << 8) + 1, 0, data, data.length,
devinfo.getTimeout(), false);
String s = getString(data, length);
assertEquals(s, Manufacturer);
// GET DESCRIPTOR (string descriptor (2))
data = getTestData(128);
length = dev.controlMsg(USB.REQ_TYPE_DIR_DEVICE_TO_HOST
| USB.REQ_TYPE_TYPE_STANDARD | USB.REQ_TYPE_RECIP_DEVICE,
USB.REQ_GET_DESCRIPTOR, (3 << 8) + 2, 0, data, data.length,
devinfo.getTimeout(), false);
s = getString(data, length);
assertEquals(s, Product);
// GET DESCRIPTOR (string descriptor (3))
data = getTestData(128);
length = dev.controlMsg(USB.REQ_TYPE_DIR_DEVICE_TO_HOST
| USB.REQ_TYPE_TYPE_STANDARD | USB.REQ_TYPE_RECIP_DEVICE,
USB.REQ_GET_DESCRIPTOR, (3 << 8) + 3, 0, data, data.length,
devinfo.getTimeout(), false);
s = getString(data, length);
assertEquals(s, SerialVersion);
// close the device
dev.close();
} catch (Exception e) {
closeOnException();
} catch (AssertionError e) {
closeOnException();
throw e;
}
}
private void closeOnException() {
try {
dev.close();
} catch (USBException e1) {
// ignore exceptions
}
}
private void validateDeviceDescriptor(byte[] data, int length) {
@@ -472,22 +489,27 @@ public class DeviceTest {
private void doWriteRead() throws Exception {
initTestData();
if (devinfo.getMode().equals(TransferMode.Bulk)) {
if (devinfo.getOutEPBulk() != -1) {
dev.writeBulk(devinfo.getOutEPBulk(), testData,
testData.length, devinfo.getTimeout(), false);
} else if (devinfo.getInEPBulk() != -1) {
dev.readBulk(devinfo.getInEPBulk(), readData, readData.length,
devinfo.getTimeout(), false);
}
} else if (devinfo.getMode().equals(TransferMode.Interrupt)) {
if (devinfo.getOutEPInt() != -1) {
dev.writeInterrupt(devinfo.getOutEPInt(), testData,
testData.length, devinfo.getTimeout(), false);
} else if (devinfo.getInEPInt() != -1) {
dev.readInterrupt(devinfo.getInEPInt(), readData,
readData.length, devinfo.getTimeout(), false);
try {
if (devinfo.getMode().equals(TransferMode.Bulk)) {
if (devinfo.getOutEPBulk() != -1) {
dev.writeBulk(devinfo.getOutEPBulk(), testData,
testData.length, devinfo.getTimeout(), false);
} else if (devinfo.getInEPBulk() != -1) {
dev.readBulk(devinfo.getInEPBulk(), readData,
readData.length, devinfo.getTimeout(), false);
}
} else if (devinfo.getMode().equals(TransferMode.Interrupt)) {
if (devinfo.getOutEPInt() != -1) {
dev.writeInterrupt(devinfo.getOutEPInt(), testData,
testData.length, devinfo.getTimeout(), false);
} else if (devinfo.getInEPInt() != -1) {
dev.readInterrupt(devinfo.getInEPInt(), readData,
readData.length, devinfo.getTimeout(), false);
}
}
} catch (Exception e) {
closeOnException();
throw e;
}
if (devinfo.doCompareData()) {
compare(testData, readData);

View File

@@ -7,7 +7,6 @@
*/
package ch.ntb.usb.test;
import ch.ntb.usb.USB;
import ch.ntb.usb.testApp.AbstractDeviceInfo;
public class MX500 extends AbstractDeviceInfo {
@@ -16,7 +15,7 @@ public class MX500 extends AbstractDeviceInfo {
public void initValues() {
setIdVendor((short) 0x046d);
setIdProduct((short) 0xc025);
setTimeout(5000);
setTimeout(2000);
setConfiguration(1);
setInterface(0);
setAltinterface(0);
@@ -24,8 +23,8 @@ public class MX500 extends AbstractDeviceInfo {
setInEPInt(0x81);
setOutEPBulk(-1);
setInEPBulk(-1);
setSleepTimeout(2000);
setMaxDataSize(USB.HIGHSPEED_MAX_BULK_PACKET_SIZE);
setSleepTimeout(5000);
setMaxDataSize(5);
setMode(TransferMode.Interrupt);
// we only read data -> don't compare
setDoCompareData(false);

View File

@@ -109,7 +109,7 @@ public class TestLibUsbJava {
}
private static int printDevice(Usb_Device dev, int level) {
int udev;
long udev;
String mfr;
String product;
String sn;

View File

@@ -1,4 +1,4 @@
#Thu Aug 24 14:28:28 CEST 2006
version.major=0
version.minor=5
version.release=4
version.release=5