• AVR Freaks

libusb and isochronous transfer

Page: < 12 Showing page 2 of 2
Author
xiaofan
Super Member
  • Total Posts : 6247
  • Reward points : 0
  • Joined: 2005/04/14 07:05:25
  • Location: Singapore
  • Status: offline
RE: libusb and isochronous transfer 2009/05/15 04:24:42 (permalink)
0
Tsuneo also recommends this function for multithread programming (with HID and isochronous transfer example).
http://www.cygnal.org/ubb/Forum9/HTML/000784.html
http://www.cygnal.org/ubb/Forum9/HTML/000292.html


http://www.cygnal.org/ubb/Forum9/HTML/000292.html
The flow of the host application is as follows.
a) Open all devices with overlapped flag at the same time.
b) In a thread, wait an event to send data to devices (WaitForSingleObject or WaitForMultipleObjects).
c) When event form the main thread occurs, call WriteFile() with "nNumberOfBytesToWrite = 256" on each device contiguously. This WriteFile returns immediately because it is an asynchronous call.
d) Wait the completion of WriteFile()s using WaitForMultipleObjects(). You can set timeout to this function.
e) If WaitForMultipleObjects() returns successfully, check the completion status with GetOverlappedResult() and loop to b) to wait next trigger event.
f) If WaitForMultipleObjects() timeout, check the completion status and call CancelIo to kill the call. Then loop to b).

In practice, as the detection of device disconnection should be considered, the flow may be a little more complicated.


I do not think Microchip is offering such examples.

  USB_Links and libusb
#21
stefanopod
Super Member
  • Total Posts : 1285
  • Reward points : 0
  • Joined: 2007/06/25 02:33:59
  • Location: Bologna,Italy
  • Status: offline
RE: libusb and isochronous transfer 2009/05/15 06:16:35 (permalink)
0
No bugs in UsbSamp by Crevars .
Be accurate, French people could take offence.
 
The key isn't in the "multiple" issue, but in the "msg" one.
I think that in my application wm_paint processing  was somehow inhibited and the message queue overflowed after 50 secs.
 
But as usual, now that my program is ok I'll try to understand why it works. No hurry.
 
And maybe Mr.Tsuneo will come in my help.
post edited by stefanopod - 2009/05/15 06:25:04

provando e riprovando
#22
xiaofan
Super Member
  • Total Posts : 6247
  • Reward points : 0
  • Joined: 2005/04/14 07:05:25
  • Location: Singapore
  • Status: offline
RE: libusb and isochronous transfer 2010/03/09 05:09:46 (permalink)
0
I will use this thread as the summary thread for libusb-win32 isochronous transfer related thread.

Other people are facing similar problems. One of them is ee_martin who ends up successfully used libusb-win32 for isochronous transfer.
Thread:
http://www.microchip.com/forums/tm.aspx?m=467499
http://www.microchip.com/forums/tm.aspx?m=468280

More example programs:
My simple libusb-win32 program for generic isochronous transfer example (by copying other people's existing program)
http://www.microchip.com/forums/fb.aspx?m=272277
http://www.microchip.com/forums/fb.aspx?m=478642

Similar code for generic isochronous transfer  from vloki
http://www.microchip.com/forums/tm.aspx?m=372725
http://www.microchip.com/forums/fb.aspx?m=477387

Similar code for generic isochronous transfer from Martin
http://www.microchip.com/forums/fb.aspx?m=479854

Other libusb-win32 examples from libusb-win32 developer Stephan Meyer.
http://www.microchip.com/forums/fb.aspx?m=480335
http://www.microchip.com/forums/fb.aspx?m=480336
http://www.microchip.com/forums/fb.aspx?m=480337

Another libusb-win32 asynchronous example from TI Calculator project
http://svn.calcforge.org/viewvc/calcforgelp/libcalccables/trunk/src/linux/link_usb.c?view=markup

One more: Open USB FXS
http://openusbfxs.wordpress.com/
http://code.google.com/p/openusbfxs/source/browse/trunk/OpenUSBFXSPCWIN32Console/OpenUSBFXS-ConsoleDriver/OpenUSBFXS-ConsoleDriver.cpp

Summary of the libusb-win32 asynchronous API (the isochronous API is part of this).

Simple explanation by the author Stephan Meyer (from his post to libusb-win32)
On Wed, Apr 25, 2007 at 4:12 AM, Stephan Meyer wrote:
>
> Ok, here's a short explanation of the asynchronous API:
>
> * Functions:
>
> int usb_xxx_setup_async(usb_dev_handle *dev, void **context, unsigned char ep);
>
> Allocates an asynchonous request for endpoint 'ep' and returns that request in 'context'.
> Returns 0 on success, < 0 on failure.
>
>
> int usb_submit_async(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_reap_async(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 ms).
>
>
> int usb_reap_async_nocancel(void *context, int timeout);
>
> Same as above but doesn't cancel the request if it times out.
>
>
> int usb_cancel_async(void *context);
>
> Cancels a request.
>
>
> int usb_free_async(void **context);
>
> Frees a request.
>
>
> * Usage:
>
> char data[1024];
> void *request;
> int read;
>
> if(usb_bulk_setup_async(dev, &request, 0x81) < 0) {
>   // error handling
> }
> if(usb_submit_async(request, data, sizeof(data)) < 0) {
>   // error handling
> }
> read =  usb_reap_async(request, 1000);
> if(read >= 0)
>   printf("read %d bytes\n", read);
> else
>   // error handling
> usb_free_async(&request);
>
>
> Hope this helps,
>
> Stephan
post edited by xiaofan - 2010/03/16 05:59:36

  USB_Links and libusb
#23
xiaofan
Super Member
  • Total Posts : 6247
  • Reward points : 0
  • Joined: 2005/04/14 07:05:25
  • Location: Singapore
  • Status: offline
RE: libusb and isochronous transfer 2010/03/09 05:13:47 (permalink)
0
On the other hand, the new libusb 1.0 Windows backend provides good alternative to libusb-win32 since it provides good documentation on asynchronous API. Unfortunately the current Windows backends (WinUSB and HID) do not support isochronous transfer. So we will have to wait for that to happen.

http://libusb.sourceforge.net/api-1.0/mtasync.html

libusb 1.0 Windows backend:
http://www.libusb.org/wiki/windows_backend

Pre-release snapshots and examples:
http://code.google.com/p/picusb/downloads/list
http://www.microchip.com/forums/tm.aspx?m=479790
post edited by xiaofan - 2010/03/09 05:23:22

  USB_Links and libusb
#24
stefanopod
Super Member
  • Total Posts : 1285
  • Reward points : 0
  • Joined: 2007/06/25 02:33:59
  • Location: Bologna,Italy
  • Status: offline
RE: libusb and isochronous transfer 2010/03/12 04:11:02 (permalink)
0
My present homework is this:writing a c# component able to do that:

having as input data only vid & pid and endpoint number , it searches the system for devices employing various drivers, detects the requested one, retrieves its characterisics and performs streaming through it.

The exercise is silly af for the utility. but interesting from a learning point of view, with the goal of avoiding when possible code duplications (so sharing as much as possible lines of code through devices having different drivers).

I'm stepping forward fairly well with usbsamp, mchpusb and winusb, both sync and async, bulk and isochronous (when existing) and partly with libusb.

But I have problems with libusb asyncronous (both bulk and isochronous).

I browsed the examples but I hardly could make out how to find a working application of asyncronous i/o (the patch of a 300ms delay makes a real application completly useless).

I see that there are new prospects about libusb 1.0, but before trying a new way (and I don't know how promising and scaring for the linux-like dialect) I would investigate better the old one.

I have also tried to deconstruct libusb 0.1 apis to lower level apis.

But the couple setup_asinc/submit_async, having the goal of hiding a DeviceIOControl call to the user, makes things complicated through the general purpose item of "Context" carrying in itself quite a lot of data stored in a not well documented way.

End of all (I omit my difficulties in porting to c# the prevalent c++ examples), my best result is a poor "timeout error -116" over the reap_async, after a reasonable result (a 997 i/o pendibg) over submit_async.

This either on bulk or isochronous read.

Any clue to make steps forward?


provando e riprovando
#25
xiaofan
Super Member
  • Total Posts : 6247
  • Reward points : 0
  • Joined: 2005/04/14 07:05:25
  • Location: Singapore
  • Status: offline
RE: libusb and isochronous transfer 2010/03/12 08:16:29 (permalink)
0
I will suggest you try WinUSB first. There are quite some good examples for WinUSB and it is relatively speaking well documented.

Then you can try the libusb 1.0 Windows backend (based on WinUSB) and not waste too much time on the libusb-win32 asynchronous API. A new backend is now being worked on (using the old libusb-Win32 device driver libusb0.sys). It will then support isochronous transfer.

Another option is to try out libusbdotnet by Travis Robinson. I think he may add libusb 1.0 Windows support soon. He already supports WinUSB. So it is a good fit for you since you use C#.
post edited by xiaofan - 2010/03/12 08:20:30

  USB_Links and libusb
#26
stefanopod
Super Member
  • Total Posts : 1285
  • Reward points : 0
  • Joined: 2007/06/25 02:33:59
  • Location: Bologna,Italy
  • Status: offline
RE: libusb and isochronous transfer 2010/03/12 08:52:37 (permalink)
0
Thanks xiaofan.

I tried winusb and it works fine.

I wanted to add to my device the libusb support.

As for libusb 1.0, I am not shure it's fit for a primitive user like me. Maybe in the future.

I tried libusbdotnet, but to no avail.

I don't like it so much (no offence to travis, his work is always excellent and his support to the forum extremely kind) but, as a wrapper to another wrapper, it hides too much what happens under the hood.

Fine if it works immeditely, not so fine if one has a secret bug to detect.

And my primary purpose is understanding the underlying mechanisms of all this stuff.

But I'll try it again to honour my motto.

provando e riprovando
#27
stefanopod
Super Member
  • Total Posts : 1285
  • Reward points : 0
  • Joined: 2007/06/25 02:33:59
  • Location: Bologna,Italy
  • Status: offline
RE: libusb and isochronous transfer 2010/03/13 03:26:19 (permalink)
0
Anyway I couldn't find in LibusbDotNet clues about asynchronous handling of libusb driver.
Probably my fault, the code isn't simple.

provando e riprovando
#28
Neiwiertz
Super Member
  • Total Posts : 2094
  • Reward points : 0
  • Joined: 2004/09/01 02:58:52
  • Status: offline
RE: libusb and isochronous transfer 2010/03/13 07:03:38 (permalink)
0
(I do not know if this could help about your topic) I just want to let know Microchip Application Libraries v2010-02-09
is available maybe this v2010-02-09 could help.

Off topic this one is cool MCP2200 USB to RS232 Demo Board from Microchip

Flying With --|Explorer 16|HardWare|SoftWare|-- Fav(s) Gallery Lists
#29
stefanopod
Super Member
  • Total Posts : 1285
  • Reward points : 0
  • Joined: 2007/06/25 02:33:59
  • Location: Bologna,Italy
  • Status: offline
RE: libusb and isochronous transfer 2010/03/13 09:14:37 (permalink)
0
I had missed it.  Thanks.

provando e riprovando
#30
xiaofan
Super Member
  • Total Posts : 6247
  • Reward points : 0
  • Joined: 2005/04/14 07:05:25
  • Location: Singapore
  • Status: offline
RE: libusb and isochronous transfer 2010/03/13 16:37:52 (permalink)
0
The new application libraries just have some bug fixes for the USB side. It will not help in this case.

As for the cool MCP2200, the cool factor is unfortunately spoied by using the Microsoft driver usbser.sys. [:@]
http://www.microchip.com/forums/tm.aspx?m=485340

  USB_Links and libusb
#31
xiaofan
Super Member
  • Total Posts : 6247
  • Reward points : 0
  • Joined: 2005/04/14 07:05:25
  • Location: Singapore
  • Status: offline
RE: libusb and isochronous transfer 2010/03/16 06:04:44 (permalink)
0
ORIGINAL: stefanopod
Anyway I couldn't find in LibusbDotNet clues about asynchronous handling of libusb driver.
Probably my fault, the code isn't simple.


I think it does not support the asynchronous API of libusb-win32 0.1 (including isochronous transfer). The latest version is supposed to support libusb 1.0 asynchronous API under Linux. Hopefully it will soon support libusb 1.0 Windows backend.

  USB_Links and libusb
#32
xiaofan
Super Member
  • Total Posts : 6247
  • Reward points : 0
  • Joined: 2005/04/14 07:05:25
  • Location: Singapore
  • Status: offline
RE: libusb and isochronous transfer 2010/03/16 06:06:15 (permalink)

  USB_Links and libusb
#33
Page: < 12 Showing page 2 of 2
Jump to:
© 2019 APG vNext Commercial Version 4.5