繁体   English   中英

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

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

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

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

我正在使用以下方法:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM