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.

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?

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);

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?

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.
If so, 
3-1) how could I access the completion handler of the listener? By using 
irp.isComplete() or irp.waitForComplete()?
3-2) how can I use the listener callback to resubmit more data?

Any advice is appreciated! Thanks in advance.

Cheers

Yukang

--- On Wed, 4/2/09, Dan Streetman <[email protected]> wrote:
From: Dan Streetman <[email protected]>
Subject: Re: [javax-usb-devel] Multiple buffers submission for UsbIrp  interface
To: [email protected]
Cc: [email protected]
Date: Wednesday, 4 February, 2009, 8:58 PM

On Wed, Feb 4, 2009 at 3:07 PM, Yukang Guo <[email protected]> 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
> [email protected]
> 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
[email protected]
https://lists.sourceforge.net/lists/listinfo/javax-usb-devel

Reply via email to