bzkrtmurat
bzkrtmurat

Reputation: 189

Read data from usb device in libusb with java(usb4java)

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.

Upvotes: 3

Views: 2990

Answers (1)

rajatksud
rajatksud

Reputation: 31

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.

Upvotes: 0

Related Questions