On Mon, 12 Apr 2004, Francisco Fernandez Velasco wrote: > Hi there, > > I've a doubt related to a scanner device I'm accessing to through the > javax-usb API. To send to device the bytes that order it starts image > scanning works fine. I use syncSubmit in its OUT PIPE and the scanner > works fine!! > The matter is that, when retrieving the image, I use different UsbIrps > (one per image chunk I retrieve), but the problem is that I have NO way > to know when to stop requesting bytes. Is there any way to resolve when > the device has no data to send? Is it correct to assume that an UsbIrp > with actualLenght set as zero would mean that there's nothing else to > send?
Do you have the specs for the scanner? Is it a standard protocol? There is really no way of guessing how the scanner will behave. It probably sends the data in a format such as you can actually know how many packets to expect. If it does send packets of size 0 a reasonable guess would be that it is "done". > > Is this piece of code correct? > do { > //IN PIPE (device to host) > UsbIrp usbIrp = inPipe.createUsbIrp(); > usbIrp.setAcceptShortPacket( true ); > usbIrp.setLength( 1024 ); > usbIrp.setOffset( 0 ); > usbIrp.setData ( new byte[ 1024 ] ); > > try { > //SYNC REQUEST: Locked till device response!! > inPipe.syncSubmit( usbIrp ); > } catch ( Exception e ) { > printStackTrace( e ); > } > //Storing image data for later use!! > buffer.append ( usbIrp.getData() ); > } while ( usbIrp.getActualLength () != 0); Looks ok (assuming you actually get a packet of length 0). However, you can reuse your UsbIrp. To get better throughput, create a list of UsbIrps, say 20 or so, and submit that. That will probably both lower the CPU usage and increase the bandwith you can use a lot. //Roger Lindsjö ------------------------------------------------------- This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id70&alloc_id638&op=click _______________________________________________ javax-usb-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/javax-usb-devel