Discussion:
[libusb] libusb_bulk_transfer() return timeout error and transferred set to 0
benjamin_t
2014-01-09 04:14:24 UTC
Permalink
Hi,
I'm attempting to write to a bulk endpoint with libusb_bulk_transfer,
and got a strange problem. It returns with a TIMEOUT_ERROR, and the
transferred parameter was set to 0, which indicates no data was sent.

The interface descriptor info is as below:
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 4
bInterfaceClass 220 Diagnostic
bInterfaceSubClass 160
bInterfaceProtocol 176
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0019 1x 25 bytes
bInterval 10
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x01 EP 1 OUT
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0019 1x 25 bytes
bInterval 10
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x82 EP 2 IN
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 10
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x02 EP 2 OUT
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 10

And here is my test code
int rv = 0;
rv = libusb_init(NULL);
if (rv < 0) {
std::cout << "*** initial USB lib failed!" << std::endl;
return -1;
}
libusb_set_debug(NULL, 4);
struct libusb_device_handle *usb_handle;
usb_handle = libusb_open_device_with_vid_pid(NULL, USB_VENDOR_ID,
USB_PRODUCT_ID);
int ret = libusb_claim_interface(usb_handle, 0);

unsigned char read_buf[64];
unsigned char send_buf[25] = {0};
int transferred;
ret = libusb_bulk_transfer(usb_handle, 0x2, send_buf, 64, &transferred,
1000);
std::cout << "tran " << transferred << std::endl; // output 0
std::cout << ret << std::endl; // output
-7
libusb_bulk_transfer(usb_handle, 0x82, read_buf, 64, &transferred,
1000);
PrintBuf(read_buf, 64);

The code above works fine when 0x2 and 0x82 was set to 0x1 and 0x81. It
seems like the 0x2 endpoint was not working. Any idea what would cause that?
Thanks in advance!






--
View this message in context: http://libusb.6.n5.nabble.com/libusb-bulk-transfer-return-timeout-error-and-transferred-set-to-0-tp5712761.html
Sent from the LibUSB Dev mailing list archive at Nabble.com.
benjamin_t
2014-01-09 06:25:13 UTC
Permalink
I've solved this problem. It happened because I had run another program which
incurred a TIMEOUT_ERROR before this one.
I tried to call libusb_clear_halt() before calling libusb_bulk_transfer(),
then the problem gone.
But now I have another problem. When I try to send several larger data
buffer sequently, like 4096 bytes, I get the output like this:
tran 4096
0
tran 192
-7
tran 128
-7
tran 128
-7
tran 128
-7
tran 128
-7
It seems like only the first sending was successful, and after the first
TIMEOUT, all the rest can send only 128 bytes. This looks wired to me,
please help. Should I try to use other functions?



--
View this message in context: http://libusb.6.n5.nabble.com/libusb-bulk-transfer-return-timeout-error-and-transferred-set-to-0-tp5712761p5712762.html
Sent from the LibUSB Dev mailing list archive at Nabble.com.
benjamin_t
2014-01-09 14:49:21 UTC
Permalink
OK, I've solved the problem myself. I split the buffer into 64 bytes manually
and it worked fine.



--
View this message in context: http://libusb.6.n5.nabble.com/libusb-bulk-transfer-return-timeout-error-and-transferred-set-to-0-tp5712761p5712772.html
Sent from the LibUSB Dev mailing list archive at Nabble.com.

Loading...