libusb_bulk_transfer究竟将数据写入?

时间:2015-04-08 07:37:36

标签: c linux usb bulk libusb

我在linux上使用libusb-1.0和大容量存储设备kingston datatrveler2.0

通过使用'lsusb -v',我发现EP_OUT地址是0x02,EP_IN地址是0x81。 我的代码片段如下:

            // 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);
            }

输出上述代码:

Bulk transfer success
Data written : XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Bulk read failed
LIBUSB_ERROR_TIMEOUT

我的问题是成功的bulk_transfer将数据写入的确切位置是什么? 如何读回相同的数据?为什么我读取TIMEOUT错误?

注意: 我经历了以下问题,但我不清楚,仍然卡住了。 libusb-1.0 - Where does the data go after a successful libusb_bulk_transfer() call?

0 个答案:

没有答案