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 * Method: usb_open
* Signature: (Lch/ntb/usb/Usb_Device;)I * 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) (JNIEnv *env, jclass obj, jobject dev)
{ {
clearLibusbJavaError(); clearLibusbJavaError();
@@ -558,7 +558,7 @@ JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1open
struct usb_device *device; struct usb_device *device;
for (device = tmpBus->devices; device; device = device->next) { for (device = tmpBus->devices; device; device = device->next) {
if (device->devnum == devnum){ 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 * Signature: (I)I
*/ */
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1close 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(); clearLibusbJavaError();
return (jint) usb_close((usb_dev_handle *) dev_handle); 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 * Signature: (II)I
*/ */
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1set_1configuration 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(); clearLibusbJavaError();
return usb_set_configuration((usb_dev_handle *) dev_handle, configuration); 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 * Signature: (II)I
*/ */
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1set_1altinterface 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(); clearLibusbJavaError();
return usb_set_altinterface((usb_dev_handle *) dev_handle, alternate); 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 * Signature: (II)I
*/ */
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1clear_1halt 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(); clearLibusbJavaError();
return usb_clear_halt((usb_dev_handle *) dev_handle, (unsigned) ep); 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 * Signature: (I)I
*/ */
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1reset 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(); clearLibusbJavaError();
return usb_reset((usb_dev_handle *) dev_handle); 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 * Signature: (II)I
*/ */
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1claim_1interface 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(); clearLibusbJavaError();
return usb_claim_interface((usb_dev_handle *) dev_handle, interface); 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 * Signature: (II)I
*/ */
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1release_1interface 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(); clearLibusbJavaError();
return usb_release_interface((usb_dev_handle *) dev_handle, interface); 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 * Signature: (IIIII[BII)I
*/ */
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1control_1msg 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(); clearLibusbJavaError();
jbyte *bytes = env->GetByteArrayElements(jbytes, NULL); 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; * Signature: (III)Ljava/lang/String;
*/ */
JNIEXPORT jstring JNICALL Java_ch_ntb_usb_LibusbJava_usb_1get_1string 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(); clearLibusbJavaError();
char string[256]; char string[256];
@@ -687,7 +687,7 @@ JNIEXPORT jstring JNICALL Java_ch_ntb_usb_LibusbJava_usb_1get_1string
* Signature: (II)Ljava/lang/String; * Signature: (II)Ljava/lang/String;
*/ */
JNIEXPORT jstring JNICALL Java_ch_ntb_usb_LibusbJava_usb_1get_1string_1simple 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(); clearLibusbJavaError();
char string[256]; char string[256];
@@ -703,7 +703,7 @@ JNIEXPORT jstring JNICALL Java_ch_ntb_usb_LibusbJava_usb_1get_1string_1simple
* Signature: (IBBI)Ljava/lang/String; * Signature: (IBBI)Ljava/lang/String;
*/ */
JNIEXPORT jstring JNICALL Java_ch_ntb_usb_LibusbJava_usb_1get_1descriptor 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(); clearLibusbJavaError();
char *string = (char *) malloc(size * sizeof(char)); 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; * Signature: (IIBBI)Ljava/lang/String;
*/ */
JNIEXPORT jstring JNICALL Java_ch_ntb_usb_LibusbJava_usb_1get_1descriptor_1by_1endpoint 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(); clearLibusbJavaError();
char *string = (char *) malloc(size * sizeof(char)); 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 * Signature: (II[BII)I
*/ */
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1bulk_1write 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(); clearLibusbJavaError();
jbyte *bytes = env->GetByteArrayElements(jbytes, NULL); 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 * Signature: (II[BII)I
*/ */
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1bulk_1read 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(); clearLibusbJavaError();
char *bytes = (char *) malloc(size * sizeof(char)); 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 * Signature: (II[BII)I
*/ */
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1interrupt_1write 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(); clearLibusbJavaError();
jbyte *bytes = env->GetByteArrayElements(jbytes, NULL); 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 * Signature: (II[BII)I
*/ */
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1interrupt_1read 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(); clearLibusbJavaError();
char *bytes = (char *) malloc(size * sizeof(char)); 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 * Class: ch_ntb_usb_LibusbJava
* Method: usb_open * 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); (JNIEnv *, jclass, jobject);
/* /*
* Class: ch_ntb_usb_LibusbJava * Class: ch_ntb_usb_LibusbJava
* Method: usb_close * Method: usb_close
* Signature: (I)I * Signature: (J)I
*/ */
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1close JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1close
(JNIEnv *, jclass, jint); (JNIEnv *, jclass, jlong);
/* /*
* Class: ch_ntb_usb_LibusbJava * Class: ch_ntb_usb_LibusbJava
* Method: usb_set_configuration * Method: usb_set_configuration
* Signature: (II)I * Signature: (JI)I
*/ */
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1set_1configuration JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1set_1configuration
(JNIEnv *, jclass, jint, jint); (JNIEnv *, jclass, jlong, jint);
/* /*
* Class: ch_ntb_usb_LibusbJava * Class: ch_ntb_usb_LibusbJava
* Method: usb_set_altinterface * Method: usb_set_altinterface
* Signature: (II)I * Signature: (JI)I
*/ */
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1set_1altinterface JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1set_1altinterface
(JNIEnv *, jclass, jint, jint); (JNIEnv *, jclass, jlong, jint);
/* /*
* Class: ch_ntb_usb_LibusbJava * Class: ch_ntb_usb_LibusbJava
* Method: usb_clear_halt * Method: usb_clear_halt
* Signature: (II)I * Signature: (JI)I
*/ */
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1clear_1halt JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1clear_1halt
(JNIEnv *, jclass, jint, jint); (JNIEnv *, jclass, jlong, jint);
/* /*
* Class: ch_ntb_usb_LibusbJava * Class: ch_ntb_usb_LibusbJava
* Method: usb_reset * Method: usb_reset
* Signature: (I)I * Signature: (J)I
*/ */
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1reset JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1reset
(JNIEnv *, jclass, jint); (JNIEnv *, jclass, jlong);
/* /*
* Class: ch_ntb_usb_LibusbJava * Class: ch_ntb_usb_LibusbJava
* Method: usb_claim_interface * Method: usb_claim_interface
* Signature: (II)I * Signature: (JI)I
*/ */
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1claim_1interface JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1claim_1interface
(JNIEnv *, jclass, jint, jint); (JNIEnv *, jclass, jlong, jint);
/* /*
* Class: ch_ntb_usb_LibusbJava * Class: ch_ntb_usb_LibusbJava
* Method: usb_release_interface * Method: usb_release_interface
* Signature: (II)I * Signature: (JI)I
*/ */
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1release_1interface JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1release_1interface
(JNIEnv *, jclass, jint, jint); (JNIEnv *, jclass, jlong, jint);
/* /*
* Class: ch_ntb_usb_LibusbJava * Class: ch_ntb_usb_LibusbJava
* Method: usb_control_msg * Method: usb_control_msg
* Signature: (IIIII[BII)I * Signature: (JIIII[BII)I
*/ */
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1control_1msg 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 * Class: ch_ntb_usb_LibusbJava
* Method: usb_get_string * 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 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 * Class: ch_ntb_usb_LibusbJava
* Method: usb_get_string_simple * 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 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 * Class: ch_ntb_usb_LibusbJava
* Method: usb_get_descriptor * 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 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 * Class: ch_ntb_usb_LibusbJava
* Method: usb_get_descriptor_by_endpoint * 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 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 * Class: ch_ntb_usb_LibusbJava
* Method: usb_bulk_write * Method: usb_bulk_write
* Signature: (II[BII)I * Signature: (JI[BII)I
*/ */
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1bulk_1write 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 * Class: ch_ntb_usb_LibusbJava
* Method: usb_bulk_read * Method: usb_bulk_read
* Signature: (II[BII)I * Signature: (JI[BII)I
*/ */
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1bulk_1read 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 * Class: ch_ntb_usb_LibusbJava
* Method: usb_interrupt_write * Method: usb_interrupt_write
* Signature: (II[BII)I * Signature: (JI[BII)I
*/ */
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1interrupt_1write 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 * Class: ch_ntb_usb_LibusbJava
* Method: usb_interrupt_read * Method: usb_interrupt_read
* Signature: (II[BII)I * Signature: (JI[BII)I
*/ */
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1interrupt_1read 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 * Class: ch_ntb_usb_LibusbJava

View File

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

View File

@@ -8,6 +8,8 @@ build.dir.bin=bin
# filenames # filenames
build.lib.libusb=libusb.a build.lib.libusb=libusb.a
build.lib.libusbpp=libusbpp.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.libusb=libusb.dylib
build.mac.lib.libusbpp=libusbpp.dylib build.mac.lib.libusbpp=libusbpp.dylib
build.shlib.srcname=LibusbJava.cpp build.shlib.srcname=LibusbJava.cpp

View File

@@ -2,6 +2,6 @@
#define RC_FILE_SUB_TYPE VFT2_UNKNOWN #define RC_FILE_SUB_TYPE VFT2_UNKNOWN
#define RC_PRODUCT_STR "Java LibUsb-Win32 wrapper - DLL" #define RC_PRODUCT_STR "Java LibUsb-Win32 wrapper - DLL"
#define RC_FILE_NAME_STR "LibusbJava.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" #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.major=0
version.minor=2 version.minor=2
version.micro=1 version.micro=2
version.nano=0 version.nano=0

View File

@@ -32,7 +32,7 @@
<target name="compile" depends="clean" description="--> Compile Java files"> <target name="compile" depends="clean" description="--> Compile Java files">
<mkdir dir="${project.dir.bin}" /> <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>
<target name="jar" depends="compile" description="--> Create Jar"> <target name="jar" depends="compile" description="--> Create Jar">
@@ -60,7 +60,7 @@
</target> </target>
<target name="javadoc" description="--> Create Javadoc"> <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" /> <fileset dir="${project.dir.src}" defaultexcludes="yes" />
</javadoc> </javadoc>
</target> </target>

View File

@@ -27,7 +27,7 @@ public class Device {
private int idVendor, idProduct, dev_configuration, dev_interface, private int idVendor, idProduct, dev_configuration, dev_interface,
dev_altinterface; dev_altinterface;
private int usbDevHandle; private long usbDevHandle;
private boolean resetOnFirstOpen, resetDone; private boolean resetOnFirstOpen, resetDone;
@@ -181,7 +181,7 @@ public class Device {
dev = initDevice(); dev = initDevice();
if (dev != null) { if (dev != null) {
int 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());
@@ -411,16 +411,17 @@ public class Device {
return writeInterrupt(out_ep_address, data, size, timeout, return writeInterrupt(out_ep_address, data, size, timeout,
false); false);
} }
throw new USBTimeoutException("LibusbJava.usb_bulk_write: " throw new USBTimeoutException(
+ LibusbJava.usb_strerror()); "LibusbJava.usb_interrupt_write: "
+ LibusbJava.usb_strerror());
} }
throw new USBException("LibusbJava.usb_bulk_write: " throw new USBException("LibusbJava.usb_interrupt_write: "
+ LibusbJava.usb_strerror()); + LibusbJava.usb_strerror());
} }
logger.info("length written: " + lenWritten); logger.info("length written: " + lenWritten);
if (logger.isLoggable(Level.FINEST)) { 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 + Integer.toHexString(out_ep_address) + ": " + lenWritten
+ " Bytes sent: "); + " Bytes sent: ");
for (int i = 0; i < lenWritten; i++) { for (int i = 0; i < lenWritten; i++) {
@@ -472,16 +473,16 @@ public class Device {
return readInterrupt(in_ep_address, data, size, timeout, return readInterrupt(in_ep_address, data, size, timeout,
false); false);
} }
throw new USBTimeoutException("LibusbJava.usb_bulk_read: " throw new USBTimeoutException("LibusbJava.usb_interrupt_read: "
+ LibusbJava.usb_strerror()); + LibusbJava.usb_strerror());
} }
throw new USBException("LibusbJava.usb_bulk_read: " throw new USBException("LibusbJava.usb_interrupt_read: "
+ LibusbJava.usb_strerror()); + LibusbJava.usb_strerror());
} }
logger.info("length read: " + lenRead); logger.info("length read: " + lenRead);
if (logger.isLoggable(Level.FINEST)) { 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 + Integer.toHexString(in_ep_address) + ": " + lenRead
+ " Bytes received: "); + " Bytes received: ");
for (int i = 0; i < lenRead; i++) { for (int i = 0; i < lenRead; i++) {
@@ -582,7 +583,7 @@ public class Device {
* @throws USBException * @throws USBException
* throws an USBException if the action fails * 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 { int interface_, int altinterface) throws USBException {
if (LibusbJava.usb_set_configuration(usb_dev_handle, configuration) < 0) { if (LibusbJava.usb_set_configuration(usb_dev_handle, configuration) < 0) {
usbDevHandle = 0; usbDevHandle = 0;
@@ -619,7 +620,7 @@ public class Device {
* @throws USBException * @throws USBException
* throws an USBException if the action fails * 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 { throws USBException {
if (LibusbJava.usb_release_interface(dev_handle, interface_) < 0) { if (LibusbJava.usb_release_interface(dev_handle, interface_) < 0) {
usbDevHandle = 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 * @return a handle used in future communication with the device. 0 if an
* error has occurred. * 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 * <code>usb_close</code> closes a device opened with
@@ -112,7 +112,7 @@ public class LibusbJava {
* 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_close(int dev_handle); public static native int usb_close(long dev_handle);
/** /**
* Sets the active configuration of a device * Sets the active configuration of a device
@@ -124,7 +124,7 @@ 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(int dev_handle, public static native int usb_set_configuration(long dev_handle,
int configuration); int configuration);
/** /**
@@ -137,7 +137,7 @@ 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(int dev_handle, int alternate); public static native int usb_set_altinterface(long dev_handle, int alternate);
/** /**
* Clears any halt status on an endpoint. * Clears any halt status on an endpoint.
@@ -148,7 +148,7 @@ 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(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> * 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. * 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(int dev_handle); public static native int usb_reset(long dev_handle);
/** /**
* Claim an interface of a device.<br> * Claim an interface of a device.<br>
@@ -178,7 +178,7 @@ 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(int dev_handle, int interface_); public static native int usb_claim_interface(long dev_handle, int interface_);
/** /**
* Releases a previously claimed interface * Releases a previously claimed interface
@@ -190,7 +190,7 @@ 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(int dev_handle, public static native int usb_release_interface(long dev_handle,
int interface_); int interface_);
// Control Transfers // Control Transfers
@@ -209,7 +209,7 @@ 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(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 request, int value, int index, byte[] bytes, int size,
int timeout); int timeout);
@@ -223,7 +223,7 @@ 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(int dev_handle, int index, public static native String usb_get_string(long dev_handle, int index,
int langid); int langid);
/** /**
@@ -236,13 +236,13 @@ 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(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 * Retrieves a descriptor from the device identified by the type and index
* of the descriptor from the default control pipe.<br> * of the descriptor from the default control pipe.<br>
* <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. * for a function that allows the control endpoint to be specified.
* *
* @param dev_handle * @param dev_handle
@@ -254,7 +254,7 @@ 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(int dev_handle, byte type, public static native String usb_get_descriptor(long dev_handle, byte type,
byte index, int size); byte index, int size);
/** /**
@@ -271,7 +271,7 @@ 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(int dev_handle, public static native 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);
// Bulk Transfers // Bulk Transfers
@@ -286,7 +286,7 @@ 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(int dev_handle, int ep, public static native int usb_bulk_write(long dev_handle, int ep,
byte[] bytes, int size, int timeout); byte[] bytes, int size, int timeout);
/** /**
@@ -300,7 +300,7 @@ 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(int dev_handle, int ep, public static native int usb_bulk_read(long dev_handle, int ep,
byte[] bytes, int size, int timeout); byte[] bytes, int size, int timeout);
// Interrupt Transfers // Interrupt Transfers
@@ -315,7 +315,7 @@ 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(int dev_handle, int ep, public static native int usb_interrupt_write(long dev_handle, int ep,
byte[] bytes, int size, int timeout); byte[] bytes, int size, int timeout);
/** /**
@@ -329,7 +329,7 @@ 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(int dev_handle, int ep, public static native int usb_interrupt_read(long dev_handle, int ep,
byte[] bytes, int size, int timeout); byte[] bytes, int size, int timeout);
/** /**

View File

@@ -44,7 +44,7 @@ public class Usb_Config_Descriptor extends Usb_Descriptor {
private int extralen; 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 * @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 * @return the alternate setting
*/ */

View File

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

View File

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

View File

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

View File

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

View File

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