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