Hi, I apologize if your guys receive this twice, it looks like my original
post did not go through.  maybe I because I attached a html file?

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 enclosed comparison between the legacy USB Trace and libUSBTrace
different in this email.

My code is as following:
(WriteCallback is a static function)
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


Here are the USBTrace comparison.


Text Compare
Produced: 8/3/2012 8:48:36 AM

Mode:  All
Left file: C:\temp\USB\LegacyWrite.txt     Right file:
F:\LibUsbWriteTrace.txt
[ TXT Log File Generated By USBTrace ]
                      =  [ TXT Log File Generated By USBTrace ]

------------------------------------------------------------------------
--------- Request # 0 ----[OUT]----
                     <> --------- Request # 1 ----[OUT]----
------------------------------------------------------------------------

                     =
URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER
                        URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER

Length: 0x80
                         Length: 0x80
USBD Status: USBD_STATUS_SUCCESS (0x0)
                         USBD Status: USBD_STATUS_SUCCESS (0x0)
EndpointAddress: 0x2
                         EndpointAddress: 0x2
------------------------------------------------------------------------
PipeHandle: 0xFFFFFA800D63FDE8
                      <> PipeHandle: 0xFFFFFA8009BF68C8
------------------------------------------------------------------------
TransferFlags: 0x0 ( USBD_TRANSFER_DIRECTION_OUT )
                      =  TransferFlags: 0x0 ( USBD_TRANSFER_DIRECTION_OUT )
------------------------------------------------------------------------
TransferBufferLength: 0x20
                      <> TransferBufferLength: 0x1E
------------------------------------------------------------------------
TransferBuffer: 0x0
                     =  TransferBuffer: 0x0
------------------------------------------------------------------------
TransferBufferMDL: 0x118CBBB0
                     <> TransferBufferMDL: 0x9376DF0
------------------------------------------------------------------------
UrbLink: 0x0
                      =  UrbLink: 0x0

** Data **
                         ** Data **
------------------------------------------------------------------------
FB 40 01 FD 09 03 05 D0 FB F0 05 FD 02 02 40 B0 00 01 4A B0 10 00 FF B0 00
80 7F B0 00 00 00 91  <> 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30
31 32 33 34 35 36 37 38 39 3A 3B 3C 3D
------------------------------------------------------------------------

                     =
------------------------------------------------------------------------
--------- Request # 1 ----[OUT]----
                     <> --------- Request # 2 ----[OUT]----
------------------------------------------------------------------------

                     =
URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER
                        URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER

Length: 0x80
                         Length: 0x80
USBD Status: USBD_STATUS_SUCCESS (0x0)
                         USBD Status: USBD_STATUS_SUCCESS (0x0)
EndpointAddress: 0x2
                         EndpointAddress: 0x2
------------------------------------------------------------------------
PipeHandle: 0xFFFFFA800D63FDE8
                      <> PipeHandle: 0xFFFFFA8009BF68C8
------------------------------------------------------------------------
TransferFlags: 0x0 ( USBD_TRANSFER_DIRECTION_OUT )
                      =  TransferFlags: 0x0 ( USBD_TRANSFER_DIRECTION_OUT )
------------------------------------------------------------------------
TransferBufferLength: 0x20
                      <> TransferBufferLength: 0x1E
------------------------------------------------------------------------
TransferBuffer: 0x0
                     =  TransferBuffer: 0x0
------------------------------------------------------------------------
TransferBufferMDL: 0x118CBBB0
                     <> TransferBufferMDL: 0x9376DF0
------------------------------------------------------------------------
UrbLink: 0x0
                      =  UrbLink: 0x0

** Data **
                         ** Data **
------------------------------------------------------------------------
FB 40 01 FD 09 03 05 D0 FB F0 05 FD 02 02 40 B0 00 01 4A B0 10 00 FF B0 00
80 7F B0 00 00 00 91  <> 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30
31 32 33 34 35 36 37 38 39 3A 3B 3C 3D
------------------------------------------------------------------------

                     =
------------------------------------------------------------------------
--------- Request # 2 ----[IN]----
                      <> --------- Request # 3 ----[IN]----
------------------------------------------------------------------------

                     =
URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER
                        URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER

Length: 0x80
                         Length: 0x80
USBD Status: USBD_STATUS_PENDING (0x40000000)
                        USBD Status: USBD_STATUS_PENDING (0x40000000)
EndpointAddress: 0x2
                         EndpointAddress: 0x2
------------------------------------------------------------------------
PipeHandle: 0xFFFFFA800D63FDE8
                      <> PipeHandle: 0xFFFFFA8009BF68C8
------------------------------------------------------------------------
TransferFlags: 0x0 ( USBD_TRANSFER_DIRECTION_OUT )
                      =  TransferFlags: 0x0 ( USBD_TRANSFER_DIRECTION_OUT )
TransferBufferLength: 0x0
                        TransferBufferLength: 0x0
TransferBuffer: 0x0
                        TransferBuffer: 0x0
------------------------------------------------------------------------
TransferBufferMDL: 0x118CBBB0
                     <> TransferBufferMDL: 0x9376DF0
------------------------------------------------------------------------
UrbLink: 0x0
                      =  UrbLink: 0x0

------------------------------------------------------------------------
--------- Request # 3 ----[IN]----
                      <> --------- Request # 4 ----[IN]----
------------------------------------------------------------------------

                     =
URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER
                        URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER

Length: 0x80
                         Length: 0x80
USBD Status: USBD_STATUS_SUCCESS (0x0)
                         USBD Status: USBD_STATUS_SUCCESS (0x0)
EndpointAddress: 0x2
                         EndpointAddress: 0x2
------------------------------------------------------------------------
PipeHandle: 0xFFFFFA800D63FDE8
                      <> PipeHandle: 0xFFFFFA8009BF68C8
------------------------------------------------------------------------
TransferFlags: 0x0 ( USBD_TRANSFER_DIRECTION_OUT )
                      =  TransferFlags: 0x0 ( USBD_TRANSFER_DIRECTION_OUT )
------------------------------------------------------------------------
TransferBufferLength: 0x20
                      <> TransferBufferLength: 0x1E
------------------------------------------------------------------------
TransferBuffer: 0x0
                     =  TransferBuffer: 0x0
------------------------------------------------------------------------
TransferBufferMDL: 0x118CBBB0
                     <> TransferBufferMDL: 0x9376DF0
------------------------------------------------------------------------
UrbLink: 0x0
                      =  UrbLink: 0x0

------------------------------------------------------------------------

                     -+ --------- Request # 5 ----[OUT]----


                        URB_FUNCTION_ABORT_PIPE


                        Length: 0x28

                        USBD Status: USBD_STATUS_SUCCESS (0x0)

                        EndpointAddress: 0x2

                        PipeHandle: 0xFFFFFA8009BF68C8


                        --------- Request # 6 ----[OUT]----


                        URB_FUNCTION_ABORT_PIPE


                        Length: 0x28

                        USBD Status: USBD_STATUS_SUCCESS (0x0)

                        EndpointAddress: 0x2

                        PipeHandle: 0xFFFFFA8009BF68C8


                        --------- Request # 7 ----[IN]----


                        URB_FUNCTION_ABORT_PIPE


                        Length: 0x28

                        USBD Status: USBD_STATUS_SUCCESS (0x0)

                        EndpointAddress: 0x2

                        PipeHandle: 0xFFFFFA8009BF68C8


                        --------- Request # 8 ----[IN]----


                        URB_FUNCTION_ABORT_PIPE


                        Length: 0x28

                        USBD Status: USBD_STATUS_SUCCESS (0x0)

                        EndpointAddress: 0x2

                        PipeHandle: 0xFFFFFA8009BF68C8

------------------------------------------------------------------------
------------------------------------------------------------------------------
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