|
From: Stephan M. <ste...@we...> - 2007-04-24 20:12:20
|
Ok, here's a short explanation of the asynchronous API:
* Functions:
int usb=5Fxxx=5Fsetup=5Fasync(usb=5Fdev=5Fhandle *dev, void **context, unsigned char=
ep);
Allocates an asynchonous request for endpoint 'ep' and returns that reques=
t in 'context'.=20
Returns 0 on success, < 0 on failure.
int usb=5Fsubmit=5Fasync(void *context, char *bytes, int size);
Submits a previously allocated request to the device. Data pointed to by '=
bytes'
of size 'size' will be written or read to or from the device depending on =
the endpoint's
direction bit. Returns 0 on success, < 0 on failure.
int usb=5Freap=5Fasync(void *context, int timeout);
Waits for the request to finish. Returns the number of bytes written/read =
or < 0 on failure.
The request will be canceled if it doesn't complete within 'timeout' (in m=
s).
int usb=5Freap=5Fasync=5Fnocancel(void *context, int timeout);
Same as above but doesn't cancel the request if it times out.
int usb=5Fcancel=5Fasync(void *context);
Cancels a request.
int usb=5Ffree=5Fasync(void **context);
Frees a request.
* Usage:
char data[1024];
void *request;
int read;
if(usb=5Fbulk=5Fsetup=5Fasync(dev, &request, 0x81) < 0) {
// error handling
}
if(usb=5Fsubmit=5Fasync(request, data, sizeof(data)) < 0) {
// error handling
}
read =3D usb=5Freap=5Fasync(request, 1000);
if(read >=3D 0)
printf("read %d bytes\n", read);
else
// error handling
usb=5Ffree=5Fasync(&request);
Hope this helps,
Stephan
>=20
> In order to do so I need to understand first what's going on exactly...
>=20
> I'll show an example:
> /**---------------------------------------------------------------------=
---**/
> USB=5FBoolean USB=5FSubmitReceive( USB=5FHandle hUsb, void *pBuf, int32=20
> nWordsCnt )
> {
> // Submit an asynchronous read
> if ( usb=5Fsubmit=5Fasync( hUsb->pReadContext, (char *)pBuf, (nWordsCnt=20
> * 2) ) < 0 ) return USB=5FFALSE;
> else return USB=5FTRUE;
> }
>=20
> /**---------------------------------------------------------------------=
---**/
> int32 USB=5FReapReceive( USB=5FHandle hUsb, int32 nTimeout )
> {
> // The number of received bytes in the receive buffer
> int32 nUsedBytesCnt;
> // Check whether the timeout is negative
> if ( nTimeout < 0 )
> {
> // Get the read context
> USB=5FUsbContext *pContext =3D (USB=5FUsbContext *)hUsb->pReadContext;=
> // Check whether the overlap IO is completed
> if ( WaitForSingleObject(pContext->ol.hEvent, 0) !=3D=20
> WAIT=5FOBJECT=5F0 ) return -1;
> // Reap the context
> nUsedBytesCnt =3D usb=5Freap=5Fasync( hUsb->pReadContext, 0 );
> }
> else
> {
> // Reap the context
> nUsedBytesCnt =3D usb=5Freap=5Fasync( hUsb->pReadContext, nTimeout );
> }
> if ( nUsedBytesCnt =3D=3D LIBUSB=5FREAP=5FASYNC=5FTIMEOUT=5FERR )
> {
> return 0;
> }
> else if ( nUsedBytesCnt < 0 )
> {
> char *pszError =3D usb=5Fstrerror();
> return nUsedBytesCnt;
> }
> else
> {
> return (nUsedBytesCnt / 2);
> }
> }
>=20
> Those are 2 functions in the API I'm porting, the documentation on these=
=20
> functions isn't very clear tho, so I'm figuring out what every function=20
> does in order to get it to work with my driver. Hence I need to know=20
> the behaviour of the usb=5FXXX functions.=20
> But I got a reply from the author of the code, he explained me how the=20
> functions behave, and yes indeed like you said, Windows CE doesn't=20
> support asynchronous reads or writes like that. So I'll have to write=20
> some thread to get the same behaviour.
>=20
> Thanx for your reply.
>=20
> Robin
>=20
> Stephan Meyer wrote:
> >> I do need to replace it with a suitable alternative, in order to do s=
o,=20
> >> I need to know how this function behaves.
> >>
> >> Kind regards
> >> Robin
> >> =20
> >
> > I think you are taking the wrong approach. If you just want to create
> > a libusb compatible layer that sits in between your application and yo=
ur
> > special driver then you should not care about the internals of the cur=
rent
> > Windows implementation.
> >
> > All you have to do is to implement the API functions specified by usb.=
h.
> > If I had to do the job I would use windows.c as a starting point, remo=
ve
> > all platform dependent code, and reimplement this code from scratch.
> > I think this is much easier than trying to adapt the existing code to =
your
> > driver.
> >
> > Stephan
> >
> >
> > =20
> >> Stephan Meyer wrote:
> >> =20
> >>>> -----Urspr=FCngliche Nachricht-----
> >>>> Von: lib...@li...
> >>>> =20
> >>>> =20
> >>> usb=5Freap=5Fasync() is part of the DLL's undocumented=20
> >>> asynchronous API.
> >>> You can just ignore it and all other usb=5Fxxx=5Fasync() functions,=20
> >>> since WinCE doesn't support asynchronous (overlapped) IO.
> >>>
> >>> Stephan
> >>>
> >>> =20
> >>> =20
> >>>> Hello,
> >>>>
> >>>> I'm porting an application developed for windows xp to windows mobi=
le. =20
> >>>> This application uses libusb to communicate with a USB-device.
> >>>> I developed a USB driver myself for windows CE. Now I'm at the poi=
nt to=20
> >>>> port the layer between the libusb to the application to a layer bet=
ween=20
> >>>> my driver and the application. I found a call to the following fun=
ction:
> >>>> int usb=5Freap=5Fasync(void *context, int timeout);
> >>>> However, I can't find any documentation on this function. What doe=
s it=20
> >>>> do exactly=3F
> >>>>
> >>>> Kind Regards
> >>>> Robin Astle
> >>>>
> >>>> -------------------------------------------------------------------=
------
> >>>> This SF.net email is sponsored by DB2 Express
> >>>> Download DB2 Express C - the FREE version of DB2 express and take
> >>>> control of your XML. No limits. Just data. Click to get it now.
> >>>> http://sourceforge.net/powerbar/db2/
> >>>> =5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F
> >>>> Libusb-win32-devel mailing list
> >>>> Lib...@li...
> >>>> https://lists.sourceforge.net/lists/listinfo/libusb-win32-devel
> >>>>
> >>>> =20
> >>>> =20
> >>> =5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F
> >>> SMS schreiben mit WEB.DE FreeMail - einfach, schnell und
> >>> kostenguenstig. Jetzt gleich testen! http://f.web.de/=3Fmc=3D021192
> >>>
> >>>
> >>> --------------------------------------------------------------------=
-----
> >>> This SF.net email is sponsored by DB2 Express
> >>> Download DB2 Express C - the FREE version of DB2 express and take
> >>> control of your XML. No limits. Just data. Click to get it now.
> >>> http://sourceforge.net/powerbar/db2/
> >>> =5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F
> >>> Libusb-win32-devel mailing list
> >>> Lib...@li...
> >>> https://lists.sourceforge.net/lists/listinfo/libusb-win32-devel
> >>>
> >>>
> >>>
> >>> =20
> >>> =20
> >> ---------------------------------------------------------------------=
----
> >> This SF.net email is sponsored by DB2 Express
> >> Download DB2 Express C - the FREE version of DB2 express and take
> >> control of your XML. No limits. Just data. Click to get it now.
> >> http://sourceforge.net/powerbar/db2/
> >> =5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F
> >> Libusb-win32-devel mailing list
> >> Lib...@li...
> >> https://lists.sourceforge.net/lists/listinfo/libusb-win32-devel
> >>
> >> =20
> >
> >
> > =5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F
> > SMS schreiben mit WEB.DE FreeMail - einfach, schnell und
> > kostenguenstig. Jetzt gleich testen! http://f.web.de/=3Fmc=3D021192
> >
> >
> > ----------------------------------------------------------------------=
---
> > This SF.net email is sponsored by DB2 Express
> > Download DB2 Express C - the FREE version of DB2 express and take
> > control of your XML. No limits. Just data. Click to get it now.
> > http://sourceforge.net/powerbar/db2/
> > =5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F
> > Libusb-win32-devel mailing list
> > Lib...@li...
> > https://lists.sourceforge.net/lists/listinfo/libusb-win32-devel
> >
> >
> >
> > =20
>=20
>=20
> ------------------------------------------------------------------------=
-
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> =5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F
> Libusb-win32-devel mailing list
> Lib...@li...
> https://lists.sourceforge.net/lists/listinfo/libusb-win32-devel
>=20
=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F
SMS schreiben mit WEB.DE FreeMail - einfach, schnell und
kostenguenstig. Jetzt gleich testen! http://f.web.de/=3Fmc=3D021192
|