On Tue, Feb 10, 2009 at 6:11 PM, Yukang Guo <yukang_...@yahoo.co.uk> wrote:
> Hi Dan,
>
> Thank you very much for you reply. I find they are quite helpful. But I am
> still confused on some points.
>
> My device continuously sends data through USB to PC as an interrupt-based
> mode, i.e. each time when device get certain amount of data, it stops
> sampling data and starts to send them to PC. The sampling resumes until the
> send event is finished.

I suspect you mean that it sends BULK-type data...if you really do
mean that your device sends data on an interrupt pipe, the transfer
capacity will be much, much less than bulk.  And, you should use
UsbIrps with a buffer the size of maxPacketSize of your interrupt
pipe.  But again, I think it's unlikely your device is sending large
amounts of data on an interrupt pipe.

>
> According to the behaviour of my device and your advice, I guess
> 1) I should use async submissions.
> 2) I should send multiple UsbIrps.
>
> Now here are my questions:
>
> 1) Since we could only submit one buffer per UsbIrp, is using a single large
> buffer by using the offsets and length parameters for multiple UsbIrps the
> same as using one small buffer for each UsbIrp? Will the efficiency be
> affected?

I don't think either way is more or less efficient from a lower level
perspective.  It depends on whether your data processing code has an
easier time with one large buffer or many smaller buffers.  You could
also use the simple asyncSubmit(byte[]) method, which is very simple.

>
> 2) For using multiple UsbIrps,
> 2-1) Shall I use a list of UsbIrps and create the UsbIrps and setData() for
> each UsbIrp beforehand and then pipe.asyncSubmit(irpList) one?
> e.g.
> for(i=0;i<N;i++){
>    irp = pipe.createUsbIrp();
>    irp.setData(different buffers/different location of one large buffer);
>    irpList.add(irp);
> }
> pipe.asyncSubmit(irpList);

You can - but this is only optimized in the Linux implementation for
Isochronous submissions.

>
> 2-2)Or shall I just use a loop(while/for)?
> e.g.
> while(irpNum < N){
>    irp = pipe.createUsbIrp();
>    irp.setData(buffer);
>    pipe.asyncSubmit(irp);
> }
> Which one shall I use? Are the efficiencies of these two methods the same?

For interrupt, bulk, or control, the implementation code will
basically handle them the same.

>
> 3) Could you give some more details on using UsbPipeListener?
> To my knowledge
> - a UsbPipeListener should be add to the pipe
> - each time when a data transfer finishes on a pipe, the listener will
> receive a corresponding event(event type depends on whether the data are
> transferred correctly). The transferred data is provided by submission.
> - when all of the submissions are finish, the listener need to be removed.

Right.  You don't have to remove the listener after your submissions
are done, you can leave it there until your program exits and/or you
are done with the device and/or pipe completely.

Also, don't forget you can submit a new UsbIrp from the pipe listener
event handler - so for example, if you are planning on receiving 500MB
from the device, you don't need to submit 500 UsbIrps with 1MB each.
You can submit 10 or 20 UsbIrps with 32K buffers each (I just made
those numbers up - use whatever you feel is appropriate for your
device needs), and in your pipe listener event handler, pass the
incoming data on to a data handler and then re-submit a new UsbIrp.
That way you will always have UsbIrps "pending".

You can re-submit the same completed UsbIrp you just received, but you
have to "reset" it - creating a new one is easier.  Java is really
good at garbage collection these days anyway.

> If so,
> 3-1) how could I access the completion handler of the listener? By using
> irp.isComplete() or irp.waitForComplete()?

No, if you use a pipe listener event handler you will never need to
use those methods.  Those are only needed if you are *not* using the
pipe listener.  The UsbIrps will be complete when your handler gets
them.

> 3-2) how can I use the listener callback to resubmit more data?

something like this pseudocode:

myListener = new UsbPipeListener() {
  public void dataEventOccurred(UsbPipeDataEvent event) {
    handleNewData(event.getData(), event.getActualLength());
    getUsbPIpe().asyncSubmit(new byte[myDataBufferSize]);
  }
  public void errorEventOccurred(UsbPipeErrorEvent event) {
    handleAnError();
  }

>
> Any advice is appreciated! Thanks in advance.
>
> Cheers
>
> Yukang
>
> --- On Wed, 4/2/09, Dan Streetman <ddstr...@ieee.org> wrote:
>
> From: Dan Streetman <ddstr...@ieee.org>
> Subject: Re: [javax-usb-devel] Multiple buffers submission for UsbIrp
> interface
> To: yukang_...@yahoo.co.uk
> Cc: javax-usb-devel@lists.sourceforge.net
> Date: Wednesday, 4 February, 2009, 8:58 PM
>
> On Wed, Feb 4, 2009 at 3:07 PM, Yukang Guo <yukang_...@yahoo.co.uk> wrote:
>> Hi Everyone,
>>
>> I have two
>  questions,
>>
>> 1) Compared to synchorous UsbPipe submission using byte[], is multiple
>> buffers submission of UsbIrp interface really more suitable for sending
>> large amount of data  in high speed?
>
> Absolutely - you have to use multiple simultaneous async submissions
> to get high throughput.
>
>>
>> 2) If the answer to Q1 is yes, is there any example for multiple buffers
>> submission for UsbIrp interface available, which I could follow?
>
> In simple psuedocode,
>
> pipe.addUsbPipeListener(myUsbIrpListener);
> while (bytesLeftToSend > 0)
>   pipe.asyncSubmit(createNewUsbIrpWithNextDataSection());
>
>
> asyncSubmit should not throw an Exception under normal circumstances,
> but it's possible so you should add a handler.
> All the results of the submissions will come back to your listener in
> an ordered manner.
>
> If you want to send data continuously and not just a single
>  buffer
> occasionally, you can send N UsbIrps (pick any number that is good for
> you) and use the listener callback to resubmit more data.  So in the
> completeion handler of the listener, do something like
>
> handleResultsOfCompletedUsbIrpIfYouNeedTo();
> pipe.asyncSubmit(createNewUsbIrpWithNextDataSection());
>
> and of course add an exception handler.  You should also handle failed
> transfers in the listener, although in my experience transfer failures
> typically mean either you sent the wrong data, or some low level
> problem happened that you really can't recover from without
> re-initializing the device or interface.
>
>
>>
>> 3) Does multiple buffers submission of UsbIrp mean  submit  multiple
> buffers
>> once per submission for one UsbIrp or submit single buffer once per
>> submission for several UsbIrp under one UsbPipe?
>
> Not sure if I understand what you are asking, but if you mean
>  multiple
> buffers per UsbIrp, that isn't possible, so no.  You submit one buffer
> per UsbIrp.  You create multple UsbIrps, set the data on them, and
> submit all of them to UsbIrp.  You can use a single large buffer if
> you want across multiple UsbIrps, by using the offset and length
> parameters.
>
>>
>> Since I am newbie in Java programming for USB device, so the questions
> above
>> might be not very professional. Any advice is highly appreciated! Thanks
> in
>> advance!
>>
>> Yukang
>>
>>
>>
> ------------------------------------------------------------------------------
>> Create and Deploy Rich Internet Apps outside the browser with
>> Adobe(R)AIR(TM)
>> software. With Adobe AIR, Ajax developers can use existing skills and code
>> to
>> build responsive, highly engaging applications that combine the power of
>> local
>> resources and data with the reach of
>  the web. Download the Adobe AIR SDK
> and
>> Ajax docs to start building applications
> today-http://p.sf.net/sfu/adobe-com
>> _______________________________________________
>> javax-usb-devel mailing list
>> javax-usb-devel@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/javax-usb-devel
>>
>>
>
>

------------------------------------------------------------------------------
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
_______________________________________________
javax-usb-devel mailing list
javax-usb-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/javax-usb-devel

Reply via email to