|
From: Tim R. <ti...@pr...> - 2013-03-14 17:37:03
|
anbaldinger wrote: > Whenever trying to send a 5 byte-frame with libusb_bulk_transfer over a > USB-to-serial-adapter, everything indicates that it worked and 'transferred' > shows that all 5 bytes were sent successfully. However nothing actually > leaves the adapter. When we use hterm for testing, everything works and the > same 5 byte-frame is sent successfully! > ... > We use the Pololu USB01B USB to Serial Adapter > http://www.pololu.com/catalog/product/391 > ... > The part of interest of the code looks like this: > > dev_handle = libusb_open_device_with_vid_pid(ctx, VENDOR_ID, > PRODUCT_ID); > if(libusb_kernel_driver_active(dev_handle, 0) == 1) { //find out if > kernel driver is attached > cout<<"Kernel Driver Active"<<endl; > if(libusb_detach_kernel_driver(dev_handle, 0) == 0) //detach it > cout<<"Kernel Driver Detached!"<<endl; > } > r = libusb_claim_interface(dev_handle, 0); > unsigned char *data = new unsigned char[5]; //data to write > data[0]=255; > data[1]=1; > data[2]=0; > data[3]=16; > data[4]=16; > int r, actual; > r = libusb_bulk_transfer(dev_handle, 0x01, data, 5, &actual, 500); > > libusb_bulk_transfer returns 0 for success and actual is 5 for the sent 5 > bytes. No errors at all! > But the adapter doesn't transmit the bytes. Are you sure the adapter doesn't need some configuration before you start to transfer? Do you need to set baud rate and parity settings? If this is USB Communication Device Class (CDC) device, there is setup to be done before you start transferring. > We had a working solution before using libusb_control_transfer, but could > only send 2 bytes at once. Now we have to send a 5 byte frame. That's why we > switched to libusb_bulk_transfer. Why do you think you were you limited to 2 bytes at once? A control transfer can send an arbitrary amount of data. > The working solution was: > > uint16_t command; > unsigned char buffer[256]; > command=(MOT_ROT+0xA)<<4|direction; > int r = 0; //for return values > r = libusb_control_transfer( dev_handle, LIBUSB_REQUEST_TYPE_VENDOR | > LIBUSB_RECIPIENT_DEVICE | LIBUSB_ENDPOINT_IN, command, 0, 0,buffer, > sizeof(buffer), 5000); That's a read request. For a write request, you want LIBUSB_ENDPOINT_OUT. -- Tim Roberts, ti...@pr... Providenza & Boekelheide, Inc. |