1

I am using libusb-1.0 on linux with the mass storage device kingston datatrveler2.0

By using 'lsusb -v' I found that EP_OUT address is 0x02 and EP_IN address is 0x81. My code snippet as follows:

            // Get the devHandle for mass storage device.
            // Detach kernel driver
            // claim the interface 

            actual = 64;
            transferred = 0;
            t_data = (char *) malloc(actual);
            memset(t_data, 'X', actual);
            retVal = libusb_bulk_transfer(devHandle, 0x02, t_data, actual, &transferred, 3000);
            // This returns success.
            if( retVal < 0)
            {
                printf("\nBulk transfer to this device failed\n");
                dump_error(retVal);
            }
            if(transferred == actual)
            {
                printf("Bulk transfer success\n");
                printf("Data written : %s\n", t_data);
            }

            retVal = libusb_bulk_transfer(devHandle, 0x81, t_data, actual, &transferred, 1000);
            // This call returns TIMEOUT error.
            if( retVal < 0)
            {
                printf("Bulk read failed\n");
                dump_error(retVal);
            }
            if(retVal >= 0 && transferred == actual)
            {
                printf("Bulk read success\n");
                printf("Data read : %s\n", t_data);
            }

Output of the above code:

Bulk transfer success
Data written : XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Bulk read failed
LIBUSB_ERROR_TIMEOUT

My question is where exactly the successful bulk_transfer wrote the data to? How do I read the same data back? Why am I getting TIMEOUT error for read?

Note : I went through the following question, but its not clear to me, still stuck. libusb-1.0 - Where does the data go after a successful libusb_bulk_transfer() call?

Community
  • 1
  • 1
kanchan
  • 65
  • 1
  • 5
  • 2
    It transferred the data to the device. What that did with it is anybody's guess. You can't necessarily read it back, unless the device supports that. You are not manipulating files here but rather performing raw USB operations. – Chris Stratton Apr 08 '15 at 07:57
  • Thanks Chris, Do you have any idea why am I getting TIMEOUT error? What does bulk_transfer tries to read when I give EP_IN as endpoint? – kanchan Apr 08 '15 at 08:19
  • in the same way that if you were reading the data off a usb device, you wouldn't care where it was coming from (just so long as it was put in a packet for you ready to read) the reverse is also true. You are sending data to the device, what it does with it is the devices responsibility – bph Apr 08 '15 at 09:27
  • 1
    so the follow on from this is that trying to read from the usb device prob doesn't make any sense as its not trying to send you any data. This will be why its timing out, the mass storage device isn't packeting up anything to send to you – bph Apr 08 '15 at 09:38
  • Thats why I am stuck, How do I read some blocks of data (raw) from USB? to say from location 0xaaaaa – kanchan Apr 08 '15 at 09:43
  • How do I ask for the device to send some data? – kanchan Apr 08 '15 at 09:46
  • Maybe point 3. from following link represents what you are trying to achieve? http://www.libusb.org/wiki/FAQ – bph Apr 08 '15 at 10:16

0 Answers0