• AVR Freaks

libusb and isochronous transfer

Page: 12 > Showing page 1 of 2
Author
stefanopod
Super Member
  • Total Posts : 1285
  • Reward points : 0
  • Joined: 2007/06/25 02:33:59
  • Location: Bologna,Italy
  • Status: offline
2009/04/19 09:12:31 (permalink)
0

libusb and isochronous transfer

In a recent thread Xiaofan posted a code snippet about isochronous transfer/ asynchronous r-w/libusb.
Since I still have problems when adapting my code about ISO from cbuilder to c# (an awful memory leak whose culprit is for me very difficult to find) and ,having suspected everything ,now I suspect USBSamp driver, I would try to migrate to libusb.
But the documentation about this stuff is very poor (ironically google brings to the same posts by xiaofan and even to posts of mine).
My question is (to Xiaofan and others): how to understand the role of usb_reap_async, of the "context" stuff, and so on?
And the the fact that libusb supports ISO, is it guaranteed?

provando e riprovando
#1

32 Replies Related Threads

    vloki
    Jo, alla!
    • Total Posts : 6806
    • Reward points : 0
    • Joined: 2007/10/15 00:51:49
    • Location: Germany
    • Status: offline
    RE: libusb and isochronous transfer 2009/04/19 11:39:56 (permalink)
    0
    Hi stefano,

    when I'm at work to morrow I'll try to check my documentation material
    about lib usb and post it wink

    Uffbasse !
    #2
    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/04/19 16:47:43 (permalink)
    0

    ORIGINAL: stefanopod
    But the documentation about this stuff is very poor (ironically google brings to the same posts by xiaofan and even to posts of mine). My question is (to Xiaofan and others): how to understand the role of usb_reap_async, of the "context" stuff, and so on?
    And the the fact that libusb supports ISO, is it guaranteed?


    To be honest, I myself have asked the same question to the libusb-win32 list and got no answer. Maybe the answer is lying in the codes. [:@]
    http://libusb-win32.svn.sourceforge.net/viewvc/libusb-win32/trunk/libusb/

      USB_Links and libusb
    #3
    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/04/19 23:02:45 (permalink)
    0
    the answer is lying in the codes. [:@]

    An answer that will never be wrong.[8|]
    Thanks anyway,Xiaofan.

    provando e riprovando
    #4
    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/04/19 23:52:17 (permalink)
    0
    From the Libusb Demo documentation in the latest Microchip USB stack:
     
     
    Libusb-Win32 is a USB Library for the Windows operating systems.  The library allows user space applications to access any USB device on Windows in a generic way without writing any line of kernel driver code. This driver allows users to have access to interrupt, bulk, and control transfers directly. 
     
     
    If isochronous tranfer is supported, the issue is kept secret.

    provando e riprovando
    #5
    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/04/20 00:45:58 (permalink)
    0
    No secret as it is an open source project.
     
    You can download the packages and open the file usb.h. The whole API is there.
     
    Or you can view it online (for the latest svn version).
    http://libusb-win32.svn.sourceforge.net/viewvc/libusb-win32/trunk/libusb/src/usb.h?view=markup
     
    But it is not well documented...

      USB_Links and libusb
    #6
    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/04/20 00:49:38 (permalink)
    0
    Actually you will understand it better than I as you understand multithread and asynchonous I/O better than I. wink
     
    Asynchronous I/O under Windows
    http://msdn.microsoft.com/en-us/library/aa365683(VS.85).aspx
     
    libusb-win32 supports synchronous I/O for bulk/interrupt transfer and asynchronous I/O for bulk/interrupt/isochronous transfer.

      USB_Links and libusb
    #7
    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/04/20 03:43:27 (permalink)
    0
     
    My knowledge about these issues is rather weak.
    Recently a C# forum respected member said that my code "faked" asynchronous I/O and was in fact synchronous.
    I didn't find a way to verify the truth of his assertion.
    Asynchronous i/o is not simple for me; if you add the complexity of mixing managed and unmanaged code and the complexity of  dealing with a garbage collector that collects only managed resources ,you'll understand my problems.
    And the result of these problems is an application hanging after several minutes of correct working.
    As a remote chance I tried the approach to libusb , but it is rather puzzling; releasing an "usb_reap_async" function, without explaining anywhere the meaning of that "reap" word is strange enough.
    But, as you say, the truth is lying in the codes (this statement of yours smells of oriental wisdom).
    I'll report any sucess of my quest, thanks.
     

    provando e riprovando
    #8
    vloki
    Jo, alla!
    • Total Posts : 6806
    • Reward points : 0
    • Joined: 2007/10/15 00:51:49
    • Location: Germany
    • Status: offline
    RE: libusb and isochronous transfer 2009/04/20 05:01:56 (permalink)
    0
    Hi again.

    Here a link to the only information that I found:

    http://www.forocoches.com/foro/showthread.php?t=929663

    There are two versions on that page. German and English.
    To me it seems the guy who wrote it is German wink


    Uffbasse !
    #9
    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/04/20 07:22:04 (permalink)
    0
    Your link is useful (and unique!!).
    And offers a choice of two languages : german and german/english.
    Rather strange for a spanish site.
    I'll begin the translation from one of the languages (I don't know what is the easiest).
    Thanks a lot.
     
     

    provando e riprovando
    #10
    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/04/20 07:37:03 (permalink)
    0
    For common API between libusb-0.1 and libusb-win32 0.1, it is easier to go to the official API.
    http://libusb.sourceforge.net/doc/

    But the Windows specific extension API of libusb-win32 is not well documented.

      USB_Links and libusb
    #11
    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/04/20 07:39:24 (permalink)
    0
    By the way, libusb-1.0 (only for Linux and Mac OS X now) supports isochronous transfer and asynchronous I/O. Unfortunately there are no porting efforts for Windows yet.

    API:
    http://libusb.sourceforge.net/api-1.0/

    Maybe this will help you to understand asynchronous I/O as well.
    post edited by xiaofan - 2009/04/20 07:40:25

      USB_Links and libusb
    #12
    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/04/20 08:22:56 (permalink)
    0
    Definitely german is easier than german/english.
    As I understand:
    1) usb_isochronous_setup_async  returns a pointer  to  "context" (so the parameter is a pointer to a pointer),that is the number of the pipe I want to setup, starting from device handle, endpoint number, packet size.
    2)usb_submit_async starts an asynchronous i/o operation over the pipe I have set up with the previous function (a wrapper of ReadFile); as parameters the buffer area and the bytes to transfer.
    3)usb_reap_async collects the  bytes exchanged asynchronously ( a wrapper of GetOverlappedResult) over the pipe . "reap" because it reaps bytes as they were wheat. Herr Meyer, the author of the code, is a poet.

    Now that I understand what I have to do, I'll try to have it working.
    Usually I do the opposite.
    Thanks again.
    post edited by stefanopod - 2009/04/20 08:25:09

    provando e riprovando
    #13
    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/03 05:30:50 (permalink)
    0
    Interestinly I came across your discussion thread here. But I am not convinced that it is the bug with usbsamp yet.
     
    http://social.technet.microsoft.com/Forums/en-us/csharplanguage/thread/7c2afb92-f8d8-4491-a211-02e6097f61f5

      USB_Links and libusb
    #14
    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/03 23:12:19 (permalink)
    0
    You see, the web is small.
    I'm not convinced either.
    I have suspects over every single coin of my software.
    Now I'm studying again from scratch the overlapped I/o issue, trying to employ the c# functions, instead of the win32 APIs.
    And about libusb I had problems that I'll consider later.

    provando e riprovando
    #15
    sc6po
    Senior Member
    • Total Posts : 133
    • Reward points : 0
    • Joined: 2006/06/28 01:52:36
    • Location: France
    • Status: offline
    RE: libusb and isochronous transfer 2009/05/12 02:34:35 (permalink)
    0

    Hi,
    I'm not very accurate on this...Very very not accurate...
    But it seems to me that you are confusing two things :
       - asynchronous from isochronous asynchronous ( data stream)
       - asynchronous from async handler ( Operating system handler)
    On this link, they say that for linux, you should not use async_handler, but you can use sync_handler to handle iscochronous asynchronous data stream...
    For instance, you could also, but it is not recommanded, use async_handler to handle isochronous synchronous data stream...
    You got to know waht asynchronisation you are talking about...
    http://http://www.chineselinuxuniversity.net/courses/application/guides/21934.shtml

    Am I spaced out?
    #16
    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/12 06:50:15 (permalink)
    0
    I'm talking about calling asynchronously the readfile function over the isochronous pipe (all the getoverlappedresult/waitforsigleobject issues--nothing to do with the async parameter in isochronous transfer).
    The examples I modified are working in that way (strange enough changing readfile to writefile changes nothing--matters only the direction of the pipe(????my ignorance is deep!!)).
    Now I'm trying to port my code to c#, employing the c# functions if I can, and not employing win32 APIs.
    But I have to understand better all the stuff. I have found interesting texts. No hurry.

    provando e riprovando
    #17
    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/14 23:26:56 (permalink)
    0
    Message to the multiple forums I bothered with my question:
    Eureka (I found it).
    Apparently my problem was using WaitForSingleObject in a thread performing graphical operations.
    The trick was employing MsgWaitForMultipleObjects with a single object, with bWaitAll=false and dwWakeMask=QS_PAINT.
    The program I had adapted (CyStream from Cypress support to CyUsb driver)performed USB isochronous I/O and not graphical operations; my program, I guess, messes with the WM_PAINT message and needs this modification.
    I never found such a malicious bug.
    But is this the real solution?
    Anyway now the program works.
    I won't touch anything in it anymore, or I will put a shorter timeout in my bug finding activity; I was risking a deadlock.

    provando e riprovando
    #18
    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 00:13:19 (permalink)
    0
    Glad that you've solved the problem. Google this function seems to suggest that it is rather complicated function. Anyway, anything related to multi-thread and asynchronous I/O seems to be complicated to me. And the long names of the functions make it more difficult for me. wink

    The function
    http://msdn.microsoft.com/en-us/library/ms684242(VS.85).aspx

    Interesting Discussion
    http://blogs.msdn.com/oldnewthing/archive/2005/02/17/375307.aspx
    http://blogs.msdn.com/larryosterman/archive/2004/06/02/146800.aspx

    Windows KB article about a potential problem:
    http://support.microsoft.com/kb/951322

    From here as well.
    http://msdn.microsoft.com/en-us/library/ms687032.aspx

    Use caution when calling the wait functions and code that directly or indirectly creates windows. If a thread creates any windows, it must process messages. Message broadcasts are sent to all windows in the system. A thread that uses a wait function with no time-out interval may cause the system to become deadlocked. Two examples of code that indirectly creates windows are DDE and the CoInitialize function. Therefore, if you have a thread that creates windows, use MsgWaitForMultipleObjects or MsgWaitForMultipleObjectsEx, rather than WaitForSingleObject.


      USB_Links and libusb
    #19
    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 00:20:02 (permalink)
    0
    And glad to know that it is not a bug of USBsamp driver after all.

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