From: Anand N. <and...@gm...> - 2017-08-16 22:42:58
|
@Tim I'm a little surprised by that. I would have expected you could submit CBW, read, CBW, read, in that order, all in advance, and it work just fine. However, as I said, I couldn't find support in the spec for that. - I will give it 1 more try and also send you my block of code to make sure that I am not missing something. @Chris why are you using Libusb to perform low-level file transfer? - Libusb provides me with more control over the USB hardware. Apart from data transfer, there are other aspects to the project which needs the low level USB commands for e.g. isochronous transfers. I also need to send particular data sequence to a particular set of blocks on the device which are known to break things in the past. fopen() and fprintf() being high level API’s doesn’t guarantee me anything. Also, doesn't their implement depend on the platform itself? I may be wrong with these assumptions and there may be a way to do all these things using the high level API's. Thanks & Regards Anand Nahar On Wed, Aug 16, 2017 at 2:37 PM, Chris E <sp...@gm...> wrote: > Serious question; why are you using Libusb to perform low-level file > transfer? Surely even something like fopen() and fprintf() would be much > easier and safer than low level USB commands. > > On 17 Aug. 2017 3:43 am, "Anand Nahar" <and...@gm...> wrote: > >> Hi, >> >> >> >> I am trying to transfer a chunk of raw data (say 1 GB) to/from a USB >> stick using libusb-1.0 on Ubuntu. After reading the documentation, I >> understand that the sequence to transfer data is: *command, data and >> status*. >> >> I am able to read/write raw data to different blocks *synchronously*. >> The code is: >> >> >> >> in loop: >> >> >> >> uint8_t cdb[16] >> >> memset(cdb, 0, sizeof(cdb)); >> >> cdb[0] = 0x28; // Read(10) >> >> cdb[4] = MSB_of_block_to_read_from – Changes in each loop; >> >> cdb[5] = LSB_of_block_to_read_from – Changes in each loop; >> >> cdb[7] = MSB_for_number_of_blocks_to_read; >> >> cdb[8] = LSB_for_number_of_blocks_to_read; >> >> >> >> struct command_block_wrapper cbw; >> >> memset(&cbw, 0, sizeof(cbw)); >> >> cbw.dCBWSignature[0] = 'U'; >> >> cbw.dCBWSignature[1] = 'S'; >> >> cbw.dCBWSignature[2] = 'B'; >> >> cbw.dCBWSignature[3] = 'C'; >> >> *ret_tag = tag; >> >> cbw.dCBWTag = tag++; >> >> cbw.dCBWDataTransferLength = length_of_actual_data; >> >> cbw.bmCBWFlags = direction; >> >> cbw.bCBWLUN = Logical_unit_number; >> >> // Subclass is 1 or 6 => cdb_len >> >> cbw.bCBWCBLength = cdb_len; >> >> memcpy(cbw.CBWCB, cdb, cdb_len); >> >> >> >> libusb_bulk_transfer(handle, endpoint_out, (unsigned char*)&cbw, 31, >> &size, 1000); //Command call >> >> >> >> //After all the error handling and successful return of the above control >> call, I actually read the data >> >> >> >> libusb_bulk_transfer(dev, endpoint_in, dataBuffer, length_of_actual_data, >> &size, 5000); //read data >> >> >> >> //read status, rest of the error handling and data manipulation >> >> >> >> I can read around 15 MB of data in 1 go. I run the above algo in loop and >> read the required amount of data by varying the block numbers. >> >> >> >> Now, I need to do the same thing *asynchronously*. I understand it has 5 >> elements: >> >> 1. Allocate transfer >> 2. Fill transfer >> 3. Submit transfer >> 4. Callback function >> 5. Event handler. >> >> I am unable to figure out on how should the asynchronous calls be >> designed so that the command and data calls are made back to back in a loop. >> >> Do I need to submit 2 separate transfers: 1 for command and 1 for data. >> If not, how do I design it? >> >> If we do have to submit 2 transfers, do I need to wait for command call >> to be completed before I can actually read the data? If so, would I be >> achieving significant improvement in the speed? >> >> >> >> Please let me know if you need any more information from my side. Your >> help is truly appreciated! >> >> >> Thanks & Regards >> Anand Nahar >> >> ------------------------------------------------------------ >> ------------------ >> Check out the vibrant tech community on one of the world's most >> engaging tech sites, Slashdot.org! http://sdm.link/slashdot >> _______________________________________________ >> libusb-devel mailing list >> lib...@li... >> https://lists.sourceforge.net/lists/listinfo/libusb-devel >> >> |