3

I'm reading data from usb device in java with libusb api. I'm able to write data to the device but I can not read data from device. I can read first data group (size : 1 byte) but when I want to read second data group (size : 2 byte) I'm getting the time out error (USB error 7: Control Transfer Failed: Operation timed out).

My code is like that ;

    buffer = ByteBuffer.allocateDirect(1);
    //03
    LibUsb.controlTransfer(handle,(byte) (LibUsb.REQUEST_TYPE_VENDOR | LibUsb.ENDPOINT_IN), (byte) 0xdb, (short) 0, (short) 0, buffer, 0);

    //00 04
    buffer.rewind();
    buffer = ByteBuffer.allocateDirect(2);

    transferred = LibUsb.controlTransfer(handle,(byte) (LibUsb.REQUEST_TYPE_VENDOR | LibUsb.ENDPOINT_IN), (byte) 0xf0, (short) 0x1c30, (short) 0, buffer, 0);

    if(transferred < 0){

        throw new LibUsbException("Control Transfer Failed", transferred);
    }

I have achieved this data transfer in C language, but I must do that in java. Please help me.

Edit : I'm changing timeout but there is no change in my application.

Edit : I can read 1 byte data. When I want to read 2 byte data I'm getting error.

bzkrtmurat
  • 189
  • 1
  • 3
  • 15
  • just a site note, if you allocate a new buffer you do not need to rewind() the old buffer. But it might be better to actually reuse the buffer for performance reasons. – eckes Mar 05 '15 at 08:38

1 Answers1

0

USB printer devices create more than one end-point, most likely you are addressing the endpoint which could be a read only. Use USB diagnostics freeware to understand what are the end-points when you connect your device to the host. One of the end-point will be read-write and this is meant for reading from the device.

rajatksud
  • 31
  • 3