如何使用usb4java同时读取两个扫描仪?

时间:2015-06-19 10:51:55

标签: java barcode-scanner usb4java

我有2个条形码扫描仪,我需要从扫描仪读取数据。我怎么知道哪个数据来自哪个扫描仪?据我所知,扫描仪是自动配置键盘,我使用的是Windows 8。

1 个答案:

答案 0 :(得分:0)

  

我如何知道哪些数据来自哪个扫描仪?

我使用以下方法:

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})): .*");