|
From: Kjell E. A. <kje...@ta...> - 2007-06-19 13:21:22
|
=20
After having used libusb-win32 exstensively for more than a year I have
come across a problem with usb_bulk_read().
After several hours of errorfree communication, an usb bulk read package
is lost (it shows on a SW bus analyzer).
=20
=20
A bulk endpoint is continously read like this :
=20
while ( ! TerminateThread )
{
i =3D usb_bulk_read( pDevH, 0x82, buffer, 64, 1000 ); // 1 sec
timeout
if ( i > 0 )
process the data
else if ( i !=3D TIMEOUT )
process error
}
=20
Q1 : Can anybody confirm that using the libusb API in this way may
result in lost packages ?
=20
The plan now is to try using the async API with 2 buffers (ping-pong)
like shown below and check if the problem disappears :
=20
i =3D 0;
i +=3D usb_bulk_setup_async( pDevH, &context1, 0x82 );
i +=3D usb_bulk_setup_async( pDevH, &context2, 0x82 );
i +=3D usb_submit_async( context1, ibuf1, 64 );
i +=3D usb_submit_async( context2, ibuf2, 64 );
if ( i !=3D 0 )
printf( "\nErrors : %d", i ); // Close down, replug etc. ??
=20
while ( ! TerminateThread ) =20
{
//--- Buffer 1 ---
i =3D usb_reap_async( context1, INFINITE ); // INIFINITE =3D -1
if ( i < 0 )
printf( "\nReap 1 error : %d", i );
else
{
printf( "\nReap 1 received : %d, %c", i, ibuf1[0] );
process data
}
i =3D 0; =20
//i +=3D usb_free_async( &context1 );
//i +=3D usb_bulk_setup_async( pDevH, &context1, 0x82 );
i +=3D usb_submit_async( context1, ibuf1, 64 );
if ( i !=3D 0 )
printf( "\nErrors : %d", i ); // Close down, replug etc. ??
=20
//--- Buffer 2 ---
i =3D usb_reap_async( context2, INFINITE );
if ( i < 0 )
printf( "\nReap 2 error : %d", i );
else
{
printf( "\nReap 2 received : %d, %c", i, ibuf2[0] );
process data
}
i =3D 0; =20
//i +=3D usb_free_async( &context2 );
//i +=3D usb_bulk_setup_async( pDevH, &context2, 0x82 );
i +=3D usb_submit_async( context2, ibuf2, 64 );
if ( i !=3D 0 )
printf( "\nErrors : %d", i ); // Close down, replug etc. ??
}
=20
i =3D usb_cancel_async( context1 );
i +=3D usb_cancel_async( context2 );
i +=3D usb_free_async( &context1 );
i +=3D usb_free_async( &context2 );
=20
Q2 : Is this the correct way to use the async API ?
=20
Q3 : Am I right in assuming that the usb_free_async() and
usb_bulk_setup_async() which is commented out inside the loop is really
unneccessary ? (it seems to work with a small limited testprogram)
=20
Any response on my three questions would be greatly appreciated !
=20
Best regards,
Kjell Eirik
|