|
From: Andrew X. <xi...@gr...> - 2006-06-21 05:26:12
|
Hi, Stephan,
I am doing a loopback ping-pong between the host and the device. I get
some -5 error after only a short while.
test\Debug>test.exe
got it open
1291 bytes read back
1291 bytes read back
1291 bytes read back
1291 bytes read back
1291 bytes read back
1291 bytes read back
1291 bytes read back
1291 bytes read back
1291 bytes read back
1291 bytes read back
1291 bytes read back
1291 bytes read back
1291 bytes read back
1291 bytes read back
1291 bytes read back
1291 bytes read back
1291 bytes read back
1291 bytes read back
1291 bytes read back
1291 bytes read back
1291 bytes read back
1291 bytes read back
-5 bytes read back
error: bulk write failed -116
error: bulk write failed -116
^C
// test.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <windows.h>
#include <process.h> /* _beginthread, _endthread */
#include <stddef.h>
#include <stdlib.h>
#include <conio.h>
#include "usb.h"
/* the device's vendor and product id */
#define MY_VID 0x03EB
#define MY_PID 0x6124
/* the device's endpoints */
#define EP_IN 0x82
#define EP_OUT 0x01
#define BUF_SIZE (64*20+11)
usb_dev_handle *dev = NULL; /* the device handle */
char tmp[BUF_SIZE];
char tmp1[BUF_SIZE];
void *context0 = NULL;
int bytesread;
usb_dev_handle *open_dev(void);
int end_thread=0;
void DeviceThread( void *dummy )
{
while(end_thread==0)
{
usb_bulk_setup_async(dev, &context0, EP_IN);
usb_submit_async(context0, tmp1, sizeof(tmp1));
bytesread=usb_reap_async(context0, INFINITE);
printf("%d bytes read back\n", bytesread);
}
_endthread();
}
usb_dev_handle *open_dev(void)
{
struct usb_bus *bus;
struct usb_device *dev;
for(bus = usb_get_busses(); bus; bus = bus->next)
{
for(dev = bus->devices; dev; dev = dev->next)
{
if(dev->descriptor.idVendor == MY_VID
&& dev->descriptor.idProduct == MY_PID)
{printf("got it open\n");
return usb_open(dev);
}
}
}
return NULL;
}
int main(void)
{
usb_init(); /* initialize the library */
usb_find_busses(); /* find all busses */
usb_find_devices(); /* find all connected devices */
for(int i=0;i<BUF_SIZE;i++)
{
tmp[i]=i;
tmp1[i]=0;
}
if(!(dev = open_dev()))
{
printf("error: device not found!\n");
return 0;
}
if(usb_set_configuration(dev, 1) < 0)
{
printf("error: setting config 1 failed\n");
usb_close(dev);
return 0;
}
if(usb_claim_interface(dev, 0) < 0)
{
printf("error: claiming interface 0 failed\n");
usb_close(dev);
return 0;
}
_beginthread(DeviceThread, 0, NULL );
for( i=0;i<100000;i++)
{int wrote;
wrote=usb_bulk_write(dev, EP_OUT, tmp, sizeof(tmp), 5000) ;
if(wrote
!= sizeof(tmp))
{
printf("error: bulk write failed %d\n", wrote);
}
Sleep(1000);
}
/* if(usb_bulk_read(dev, EP_IN, tmp1, sizeof(tmp), 5000)
!= sizeof(tmp1))
{
printf("error: bulk read failed\n");
}
*/
Sleep(500);
end_thread=1;
usb_release_interface(dev, 0);
usb_close(dev);
bool test=true;
for(i=0;i<bytesread;i++)
{
if(tmp[i]!=tmp1[i])
{
test=false;
printf("mismatch\n");
break;
}
}
if(test)
printf("received okay\n");
return 0;
}
----- Original Message -----
From: "Stephan Meyer" <ste...@we...>
To: <lib...@li...>; "Andrew Xiang"
<xi...@gr...>
Sent: Monday, June 19, 2006 4:53 PM
Subject: Re: [Libusb-win32-devel] win-libusb async read
>
> You are right. This function had a small bug that I fixed some
> weeks ago. The new version is in already the CVS.
>
> See
> http://libusb-win32.cvs.sourceforge.net/libusb-win32/libusb/src/windows.c?revision=1.44&view=markup
>
>
>
>> Stephan,
>>
>> in usb_submit_async
>>
>> if(!DeviceIoControl(c->dev->impl_info,
>> c->control_code,
>> &c->req, sizeof(libusb_request),
>> c->bytes,
>> c->size, &ret, &c->ol))
>> {
>> if(GetLastError() != ERROR_IO_PENDING)
>> {
>> usb_error("usb_submit_async: submitting request failed, "
>> "win error: %s", usb_win_error_to_string());
>> return -usb_win_error_to_errno();
>> }
>> }
>>
>> return ret;
>>
>>
>>
>> ret has the bytes_read. however, the value got returned before the value
>> is
>> updated. I think usb_submit_async should take a parameter in as a
>> &bytes_read.
>>
>> -Andrew
>>
>>
>> ----- Original Message -----
>> From: "Stephan Meyer" <ste...@we...>
>> To: <lib...@li...>; "Andrew Xiang"
>> <xi...@gr...>
>> Sent: Monday, June 19, 2006 12:44 PM
>> Subject: Re: [Libusb-win32-devel] win-libusb async read
>>
>>
>> >
>> > See
>> >
>> > http://sourceforge.net/mailarchive/message.php?msg_id=10083829
>> >
>> >
>> >
>> > > I got the simple bulk write/read to work. However, I would like to
>> > > have
>> a
>> > > thread waiting on the read all the time and process the read data
>> > > independent of the write. How would I implement async read using the
>> libusb?
>> > > anyone has an example?
>> > >
>> > > thanks
>> > > Andrew
>> > >
>> > >
>> > >
>> > > _______________________________________________
>> > > Libusb-win32-devel mailing list
>> > > Lib...@li...
>> > > https://lists.sourceforge.net/lists/listinfo/libusb-win32-devel
>> >
>> >
>> > ______________________________________________________________________
>> > XXL-Speicher, PC-Virenschutz, Spartarife & mehr: Nur im WEB.DE Club!
>> > Jetzt gratis testen! http://freemail.web.de/home/landingpad/?mc=021130
>> >
>> >
>> >
>> > _______________________________________________
>> > Libusb-win32-devel mailing list
>> > Lib...@li...
>> > https://lists.sourceforge.net/lists/listinfo/libusb-win32-devel
>> >
>>
>>
>>
>> _______________________________________________
>> Libusb-win32-devel mailing list
>> Lib...@li...
>> https://lists.sourceforge.net/lists/listinfo/libusb-win32-devel
>
>
> _____________________________________________________________________
> Der WEB.DE SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
> http://smartsurfer.web.de/?mc=100071&distributionid=000000000071
>
>
>
> _______________________________________________
> Libusb-win32-devel mailing list
> Lib...@li...
> https://lists.sourceforge.net/lists/listinfo/libusb-win32-devel
>
|