tech...@yahoo.com
unread,May 12, 2013, 1:54:13 PM5/12/13You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
Jacob,
thanks for your quick reply. Yes, I think I am honoring the array bounds. I am using the same variable to define the array size that I then use to control the loop for copying data into the buffer. Also, the 32 bit version is running fine with or without the 'magic variable'. I added code to dump the data to stdout after copying and that looks good. Then, when I look at the USB bus analyzer to see the data that is actually transmitted to the device I see that it's not the same. The same type of problem also occurs in the reverse direction.
I could get you the code if there is a way to do this without making it public. Debugging it on your end will be more tricky, because you need the USB device to talk to and the Java application to drive it. I'll think about what I could do to construct a test case that makes sense. For the time being here is one of the functions that make trouble. Maybe that gives you something to work with.
<pre>
/*----------------------------------------------------------------------------*/
/**
* Performs a control request to the default control pipe on a device.
*
* @param env the Java environment
* @param obj our Java counterpart object
* @param handle the device handle
* @param requestType USB specification Table 9-2: <code>bmRequestType</code>
* @param request USB specification Table 9-2: <code>bRequest</code>
* @param value USB specification Table 9-2: <code>wValue</code>
* @param index USB specification Table 9-2: <code>wIndex</code>
* @param bytes the data to transfer
* @param timeout the communication timeout in ms to use for the operation
*
* @return The data received from the device. In case of an OUT message
* this will be an empty array. If <code>null</code> is returend
* the call was not successful.
*/
/*----------------------------------------------------------------------------*/
JNIEXPORT jboolean JNICALL Java_com_yxis_lib_usb_LibUSB_usbControlMessage (JNIEnv *env,
jobject obj,
jint handle,
jint requestType,
jint request,
jint value,
jint index,
jintArray bytes,
jint timeout)
{
jboolean result = FALSE;
jboolean isCopy = FALSE;
// ----------------------------------------------------
// re-package the data array
// ----------------------------------------------------
int *source;
jsize size = (*env)->GetArrayLength (env, bytes);
char buffer [size];
source = (*env)->GetIntArrayElements (env, bytes, &isCopy);
// ----------------------------------------------------
// I don't know what is going on, but this line of code
// makes it work for the 64 bit compiler, even though
// it isn't actually doing anything that has impact...
// ----------------------------------------------------
unsigned int magicBuffer [size];
for (int i = 0; i < size; i++)
{
buffer [i] = (char)source [i];
}
(*env)->ReleaseIntArrayElements (env, bytes, source, JNI_ABORT);
// ----------------------------------------------------
// make the call
// ----------------------------------------------------
int callResult = usb_control_msg (handleMap [handle].deviceHandle,
CONTROL_OUT (requestType),
request,
value,
index,
buffer,
(int)size,
timeout);
// ----------------------------------------------------
// check for success. We should have exactly as many bytes
// transfered as asked for by the caller.
// ----------------------------------------------------
if (callResult == size)
{
result = TRUE;
}
return (result);
}
</pre>