How to use usb4java to read two scanners at the same time?

436 views Asked by At

I have 2 barcode scanners and I need to read the data from the scanner. How can I know which data comes from which scanner? As I know the scanners are auto config to a keyboard and I am using windows 8.

1

There are 1 answers

0
Not Relevant On

How can I know which data comes from which scanner?

I am using the following method:

public static String getBusAndDevice(final UsbDevice usbDevice) {
    // Hack: We need "DeviceId ((AbstractDevice) usbDevice).getId()" but it's not accessible!
    // usbDevice.toString() gives us the information, but we shouldn't rely on the
    // string returned by this method!
    final String toString = usbDevice.toString();
    final Matcher matcher = PATTERN_busAndDevice.matcher(toString);
    if (!matcher.matches()) {
        throw new IllegalStateException("Can't retrieve 'Bus %03d Device %03d'");
    }
    final String busAndDevice = matcher.group(1);
    return busAndDevice;
}
static final Pattern PATTERN_busAndDevice = Pattern.compile( //
  "^(Bus ([0-9]{3}) Device ([0-9]{3})): .*");