Good sirs, I have a question. The school Java project I am currently working on requires me to have a USB Barcode Scanner as an external input to be connected to my laptop. I haven't actually bought the USB Scanner since it's quite expensive for a student. So I have to gather evidence that this Scanner would work with my program.
Would the Scanner be able to read from a barcode (presumably printed off online) and store it into a variable? If so, is it true that the action event for the press of the scanner would be read exactly like a keyboard keypress? If so, what would the line of code look like?
Also, if you could post your experiences with Barcode Scanners, or give any advice, such as which Scanner to buy, that would help alot. Cheers!
I recently had to implement a scanner system to interact with java.
I used Honeywell Voyager MS9540 USB barcode scanner.
As a default the scanner sent the data straight as keyboard input - no driver required.
But it was very easy to get this model to interact directly with java rather than using a keyboard hook (to use the barcodes as variables in java, as you mentioned).
This model has a setting to emulate a serial port, you can then read the scanned data using the javax.comm package. For me, this was much better than a keyboard hook to get the barcode data because the program does not need the focus before being able to interpret a scan (I would not want to create a global keyboard hook).
My java program reads all input from the specified serial port and writes the barcode to a database. I also setup the program to pass any unrecognized barcode scans to the keyboard (any barcode that my app did not create - I used a distinct signature on my barcodes) this was so it would work as a regular barcode scanner for any other apps that might read barcodes from the keyboard.
You could probably read data directly from any USB scanner (without the serial port emulation that this model has) by doing some intensive JNI coding but I wasn't prepared to take the time to work out the native code.
To configure this particular model for serial port emulation all you do is scan a specific barcode in this document with the scanner you want to configure. It is the barcode titled "Serial Emulation Mode".
This scanner does require a driver for serial port emulation. I found the implementation instructions and the needed drivers here (under the "software" tab). Download the package titled: "Honeywell Scanning and Mobility (HSM) USB Serial Driver". The PDF titled "HSM USB Serial Driver Getting Started Guide" had the instructions.
If you are not familiar with the javax.comm API. Please read the intro in this example by Rick Proctor - it tells you where to get the jar and where to put the files (javax.comm does not come standard with most java packages).
I'm sure there are other scanner models around that have serial port emulation (I don't work for Honeywell).
Here's a somewhat stripped down version of my barcode reader class:
I know it's quite old thread but search can get you there.
This can be treated as an addition to Geronimo's answer:
For Linux OS there is no need to install drivers for barcode scanners in serial emulation mode as there is native support for USB serial ports. We use several types of Honeywell scanners and all of them work out of the box, those scanners in serial emulation shows in our systems as /dev/ttyACM0, /dev/ttyACM1 etc.
Recently we have switched from javax.comm to jssc as a java library to interface serial ports. If I remember well, under Windows 7 64bit system javax.comm library cannot read or write from/to serial port and jssc has very similar api.
The bardcode scanner I have used acted like a keyboard device (it showed up as a HID keyboard USB device in the operating system). When the barcode was scanned, it sent the code as if it was typed. No special APIs were needed to interact with it.
I realize this was an old question but figured I would add an additional solution for simulating Barcode Scanner input. This solution only works for simulating scanner input as keyboard data.
Since scanner's often just use keyboard input we can simulate this using an AutoHotkey script. Below is an example of a script:
Just replace
[BC300013]
and[BC200015]
with whatever your expected scanner input is.