0

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

4

1 回答 1

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})): .*");
于 2015-07-03T14:06:54.430 回答