Peter,
I am in debug mode, after I steped through the
libusb_handle_events_timeout first time I notice USBTrace showed up
ABORT_PIPE , the second time I call  libusb_handle_events_timeout  ,
nothing showed up in the USBTrace and the callback is called.

I found the problem, because I was running step by step, it just timeout
 that is why I got the ABORT_PIPE, if I just ran the code directly I did
not get ABORT_PIPE again.


Thanks.
John

On Thu, Aug 2, 2012 at 10:39 PM, John Chen <john...@gmail.com> wrote:

> Hi, Gurus,
> I am doing a Asynchronous Bulk call to USB, everything seems to work fine,
> but after I call the first  libusb_handle_events_timeout, I Received
> ABORT_PIPE from USBTrace, After the second
>  libusb_handle_events_timeout call, the callback receive the message. (no
> sure why I have to call  libusb_handle_events_timeout twice before I got
> the call back with that little data), I have legacy code (Windows API)
> doing the same thing but I did not receive  ABORT_PIPE from USBTrace, any
> ideas?
>
> I am using VS2008, Windows 7
>
> Also I have to call
>    err = libusb_claim_interface(this->m_handle, 0);
> Before submit, do not understand why I have to do that for this function,
> while other function seems to work without the above call.
> Thanks in advance.
>
> I attached comparison between the legacy USB Trace and libUSBTrace
> different in this email.
> (WriteCallback is a static function)
> My code is as following:
>
>  class WriteData
> {
> public:
>  int ErrorCode;
> int ByteTransfered;
> bool ExitTransfer;
>  };
>
> void LIBUSB_CALL USB_Device::WriteCallback(struct libusb_transfer
> *transfer)
> {
> WriteData* wd =(WriteData*)transfer->user_data;
>  wd->ByteTransfered=transfer->actual_length;
> wd->ErrorCode==transfer->status;
>  wd->ExitTransfer=true;
> }
>
> libusb_transfer*  USB_Device::Alloc_Transfers( const unsigned long
>  endpoint,
> const unsigned int c_uiLength,
>  unsigned char* pbBuffer,
>                                                void* userdata,
>                                              int& err)
> {
> libusb_transfer* transfer =libusb_alloc_transfer(0);
> if (!transfer)
>  {
> err=-ENOMEM;
> return NULL;
>  }
>
> libusb_fill_bulk_transfer
> (transfer,m_handle,endpoint,pbBuffer,c_uiLength,U
>  SB_Device::WriteCallback,userdata,ITP_TRANSFER_TIMEOUT);
> return transfer;
>
> }
>
>
> int USB_Device::BulkWrite(
> const unsigned long c_ulPipeNum,
>  const unsigned int c_uiLength,
> unsigned char* pbBuffer,
>  HANDLE cancelEvent)
> {
> const unsigned long endpoint=c_ulPipeNum*2;
>  WriteData* wd=new WriteData();
> wd->ExitTransfer=false;
> int err =0;
>  libusb_transfer* transfer=Alloc_Transfers(endpoint,c_uiLength,
> pbBuffer,(void*)wd,err);
>  if (!err)
> {
> err = libusb_claim_interface(this->m_handle, 0); //Do I need to claim
>
> err=libusb_submit_transfer(transfer);
> while (!wd->ExitTransfer)
>  {
> struct timeval tv = { 1, 0 };
>   err = libusb_handle_events_timeout(NULL, &tv);
>  if (err < 0)
> {
> break;
>  }
> }
> }
>
>
> if (err < 0)
> {
> libusb_cancel_transfer(transfer);
>  while (transfer)
> if (libusb_handle_events(NULL) < 0)
> break;
>  return err;
> }
>
> }
> The debug log is as following:
>
> [ 4.045232] [000006d8] libusbx: debug [libusb_claim_interface] interface 0
> [ 4.045232] [000006d8] libusbx: debug [winusb_claim_interface] claimed
> interface 0
> [ 4.046232] [000006d8] libusbx: debug [libusb_get_config_descriptor] index
> 0
> [ 4.047232] [000006d8] libusbx: debug [windows_assign_endpoints]
> (re)assigned endpoint 01 to interface 0
> [ 4.047232] [000006d8] libusbx: debug [windows_assign_endpoints]
> (re)assigned endpoint 02 to interface 0
> [ 4.048232] [000006d8] libusbx: debug [windows_assign_endpoints]
> (re)assigned endpoint 04 to interface 0
> [ 4.049232] [000006d8] libusbx: debug [windows_assign_endpoints]
> (re)assigned endpoint 86 to interface 0
> [ 4.050232] [000006d8] libusbx: debug [windows_assign_endpoints]
> (re)assigned endpoint 88 to interface 0
> [ 4.501258] [000006d8] libusbx: debug [winusb_submit_bulk_transfer]
> matched endpoint 02 with interface 0
> [ 4.501258] [000006d8] libusbx: debug [winusb_submit_bulk_transfer]
> writing 30 bytes
> [ 4.502258] [000006d8] libusbx: debug [usbi_add_pollfd] add fd 5 events 4
> [ 4.503258] [000006d8] libusbx: debug [libusb_get_next_timeout] next
> timeout in 2.997276s
> [ 4.505258] [000006d8] libusbx: debug
> [libusb_handle_events_timeout_completed] doing our own event handling
> [ 4.506258] [000006d8] libusbx: debug [handle_events] poll() 2 fds with
> timeout in 1000ms
> [ 4.507258] [000006d8] libusbx: debug [handle_events] poll() returned 1
> [ 4.508258] [000006d8] libusbx: debug [windows_handle_events] checking fd
> 3 with revents = 0000
> [ 4.509258] [000006d8] libusbx: debug [windows_handle_events] checking fd
> 5 with revents = 0004
> [ 4.510258] [000006d8] libusbx: debug [usbi_remove_pollfd] remove fd 5
> [ 4.510258] [000006d8] libusbx: debug [windows_transfer_callback] handling
> I/O completion with errcode 0
> [ 4.511258] [000006d8] libusbx: debug [usbi_handle_transfer_completion]
> transfer 005A8560 has callback 00B68CD5
>
>
>
>
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
libusbx-devel mailing list
libusbx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libusbx-devel

Reply via email to