2015-06-19 56 views
0

我有2個條形碼掃描儀,我需要從掃描儀讀取數據。我如何知道哪些數據來自哪臺掃描儀?據我所知,掃描儀是自動配置到鍵盤,我正在使用Windows 8.如何使用usb4java同時讀取兩臺掃描儀?

+0

的usb4java網站有幾個不錯的代碼片段,你試過嗎?什麼沒有用? – GregHNZ

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