You didn't mention whether you know what your printer protocol is and know you are using it correctly, or if you are completely guessing about the protocol. If you don't know the protocol, I can't help you, as I think most printer protocols are rather complicated.
However, I'll assume that you know your protocol and are using it correctly. I suggest to use larger buffers; with bulk you are not limited to the max packet size. Try 1k or more. Also, you may want to use async instead of sync. Finally, are you calling submit multiple times? You only said basically "it didn't work" but did not elaborate at all. Are you reading the entire file? Is there an exception? What is the return value from the submission (including the irp exception if any, the irp transferred length, etc)? You aren't checking any status from the submission. On Nov 6, 2007 9:12 PM, Xie, Ric <[EMAIL PROTECTED]> wrote: > > > > > Hi, > > I'm new in development using javax-usb. > > I want to use the API to write a file to an usb printer. So I modified a > part of the example code "MouseDriver" for test. It's like this: > > > > public static void driveHidMouse(UsbInterface usbInterface) > > { > > try { > > usbInterface.claim(new > UsbInterfacePolicy( ) { > > public boolean > forceClaim(UsbInterface usbInterface) { > > return > true; > > } > > }); > > > > } catch ( UsbException uE ) { > > > > System.out.println("Could not claim > interface to drive HID mouse : " + uE.getMessage()); > > return; > > } > > List usbEndpoints = > usbInterface.getUsbEndpoints(); > > UsbEndpoint usbEndpoint = null; > > for (int i=0; i<usbEndpoints.size(); i++) { > > usbEndpoint = > (UsbEndpoint)usbEndpoints.get(i); > > > > > > byte bType = usbEndpoint.getType(); > > byte bDirct = > usbEndpoint.getDirection(); > > if (UsbConst.ENDPOINT_TYPE_BULK == > usbEndpoint.getType() && UsbConst.ENDPOINT_DIRECTION_OUT == > usbEndpoint.getDirection()) > > break; > > else > > usbEndpoint = null; > > > > } > > if (null == usbEndpoint) { > > System.out.println("This HID interface > does not have the required interrupt-in endpoint."); > > return; > > } > > > > UsbPipe usbPipe = usbEndpoint.getUsbPipe(); > > int maxPacketSize = > usbEndpoint.getUsbEndpointDescriptor().wMaxPacketSize( ); > > > > try { > > usbPipe.open(); > > } catch ( UsbException uE ) { > > System.out.println("Could not open > endpoint to communicate with HID mouse : " + uE.getMessage()); > > try { usbInterface.release(); } > > catch ( UsbException uE2 ) { /* FIXME - > define why this might happen. */ } > > return; > > } > > try{ > > UsbIrp irp = usbPipe.createUsbIrp( ); > > FileInputStream inStream=new > FileInputStream("/root/workspace/test.txt"); > > byte[] buffer =new byte[maxPacketSize]; > > irp.setData(buffer); > > while ((iReadnum = > inStream.read(buffer)) != -1) { > > usbPipe.syncSubmit(irp); > > irp.setComplete(false); > > } > > > > > > } catch (UsbException uE) { > > System.out.println("Unable > to submit data buffer to HID mouse : " + uE.getMessage()); > > } > > catch(Exception e) > > { > > } > > try { > > usbPipe.close(); > > usbInterface.release(); > > } catch ( UsbException uE ) { /* FIXME - define why > this might happen. */ } > > > > System.out.println("Done driving HID mouse."); > > } > > I do not know whether my usage is right. See the red part of the code. > > When I ran the application, the printer succeeded to print something, > but it is just a small part of the file "test.txt", about 77 bytes. > > And the maxPacketSize of the endpoint is 64. Why did that happen? > > Since it is a BULK type endpoint, I think it should can transfer massive > data. So how can I make the printer print out the whole file? > > Anybody can help me? > > > > > > > > > Yours, > > Sincerely, > > Ric > > > > Best Regards! > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. > Still grepping through log files to find problems? Stop. > Now Search log events and configuration files using AJAX and a browser. > Download your FREE copy of Splunk now >> http://get.splunk.com/ > _______________________________________________ > javax-usb-devel mailing list > javax-usb-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/javax-usb-devel > > ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ javax-usb-devel mailing list javax-usb-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/javax-usb-devel