簡體   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