Hello,
I have an MT-215 before me, the development machine runs Ubuntu
Desktop 7.04, and javax-usb is at version 1.0.1. As far as I've
understood from the technical doc[1], the device simply sends input
reports on the interrupt in pipe (and sending anything to it is
usually not necessary), and as far as I can see from usbview and from
traversing the device, there is only a single
configuration-interface-endpoint.
So away I go, find the device, force-claim the interface, open the
pipe, start a runnable (like the mouse driver example). The device LED
turns on and reacts correctly when I swipe a card, but
UsbPipe.syncSubmit never returns. I've tried various methods:
submitting an Irp, submitting a byte[], attaching a PipeListener, and
attaching a DeviceListener. I never get anything from the device.
I figure I must be doing something wrong or not reading it correctly.
What ways are there to get data from a device? I've attached some
relevant code in case anyone wants details.
Mirza
[1] page 19, <http://www.magtek.com/docs/99875205.pdf>
package pressrec;
import javax.usb.*;
import javax.usb.event.UsbDeviceDataEvent;
import javax.usb.event.UsbDeviceErrorEvent;
import javax.usb.event.UsbDeviceEvent;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
class ForceClaimUsbInterfacePolicy implements javax.usb.UsbInterfacePolicy{
public boolean forceClaim(UsbInterface arg0) {
return true;
}
}
public class Application {
public static void main(String argv[]) throws UsbNotActiveException, UsbNotClaimedException, UsbDisconnectedException, UsbException, InterruptedException, SecurityException, IOException{
System.out.println("Looking for device..");
List devices = findDevices(MT215.idVendor, MT215.idProduct);
if(devices.size() == 0){
System.out.println("Couldn't find device with matching vendor and product id!");
return;
}
UsbDevice device = (UsbDevice) devices.get(0);
UsbInterface iface = (UsbInterface) device.getActiveUsbConfiguration().getUsbInterfaces().get(0);
iface.claim(new ForceClaimUsbInterfacePolicy());
UsbPipe pipe = ((UsbEndpoint) iface.getUsbEndpoints().get(0)).getUsbPipe();
pipe.open();
MT215Runnable runner = new MT215Runnable(pipe);
Thread t = new Thread(runner);
System.out.println("Driving MT215 reader, swipe away.");
System.out.println("Press Enter when done.");
t.start();
System.in.read();
runner.stop();
pipe.close();
iface.release();
System.out.println("Done!");
}
/*
* Get a List of all devices that match the specified vendor and
* product id.
*
* @param vendorId The vendor id to match.
* @param productId The product id to match.
*/
public static List findDevices(short vendorId, short productId) throws SecurityException, UsbException, UnsupportedEncodingException, UsbDisconnectedException{
return findDevices(vendorId, productId, null);
}
/*
* Get a List of all devices that match the specified vendor and
* product id. Call like findDevices(vendor, product) to start
* from the root hub.
*
* @param vendorId The vendor id to match.
* @param productId The product id to match.
* @param usbDevice The UsbDevice to start looking from.
*/
public static List findDevices(short vendorId, short productId, UsbDevice usbDevice) throws SecurityException, UsbException, UnsupportedEncodingException, UsbDisconnectedException
{
if(usbDevice == null)
usbDevice = UsbHostManager.getUsbServices().getRootUsbHub();
List list = new ArrayList();
if (vendorId == usbDevice.getUsbDeviceDescriptor().idVendor()
&& productId == usbDevice.getUsbDeviceDescriptor().idProduct())
list.add(usbDevice);
if (usbDevice.isUsbHub()) {
List devices = ((UsbHub) usbDevice).getAttachedUsbDevices();
for (int i = 0; i < devices.size(); i++)
list.addAll(findDevices(vendorId, productId,
(UsbDevice) devices.get(i)));
}
return list;
}
}
package pressrec;
import javax.usb.*;
import javax.usb.util.*;
public class MT215Runnable implements Runnable {
UsbPipe pipe = null;
boolean running = true;
MT215Runnable(UsbPipe pipe){
this.pipe = pipe;
}
public void run() {
byte[] buffer = new byte[338];
UsbIrp irp = pipe.createUsbIrp( );
irp.setData(buffer);
System.out.println("Running listener..");
while(running){
System.out.println(">>>");
try{
pipe.syncSubmit(irp);
}
catch(UsbException uex){
// abortAllSubmissions after-effect
}
for (int i = 0; i < irp.getActualLength(); i++)
System.out.print(" 0x" + UsbUtil.toHexString(irp.getData()[i]));
System.out.println("");
}
}
public void stop()
{
running = false;
pipe.abortAllSubmissions();
}
}
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
javax-usb-devel mailing list
javax-usb-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/javax-usb-devel