I have 2 barcode scanners and I need to read the data from the scanner. How can I know which data comes from which scanner? As I know the scanners are auto config to a keyboard and I am using windows 8.
Asked
Active
Viewed 421 times
0
-
The usb4java site has a few good code snippets, have you tried them? What didn't work? – GregHNZ Jun 19 '15 at 11:45
-
I tied, I can find those scanner details, but cannot get the data from the scanner, and cannot distinguish the data is from which scanner. – Fai Fabio Jun 22 '15 at 01:55
1 Answers
0
How can I know which data comes from which scanner?
I am using the following method:
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})): .*");

maskacovnik
- 3,080
- 5
- 20
- 26