Reputation: 244
I created a Java application and want to use barcode scanner in my Java application.
but don't have a device Barcode Scanner
How can I simulate a Barcode Scanner for testing my Java Application?
Upvotes: 2
Views: 9321
Reputation: 3973
I had a similar need and found the barcode-simulator project on GitHub. It covers a portion of the concerns raised in the comments, at least for the initial testing.
Still, there is nothing like the real deal. Expect that the mix of real users and real scanners are going to find unexpected holes in your application.
Provide really clear input to your clients:
If your users are clear about what the path of success looks like then it should be good.
Upvotes: 1
Reputation: 56697
It really depends on how you want the scanner to connect to the system later on.
There are scanners that just use keyboard emulation. In that case you don't need to do anything (just make sure the right input box is active when expecting barcode input).
Other scanners connect to the system through a serial port emulation (for example, there's an USB to serial driver for Symbol/Motorola and Datalogic gun scanners). In that case, you open the serial port in Java and get scanner input as serial data. To simulate this, you'd have to connect your PC to another PC using a cross-over RS232 cable and could then use Hyperterminal/Putty/[whatever there is on linux or other OSs] to send data to your PC over the serial cable.
Upvotes: 7
Reputation: 11310
If you are running your application from the console,
Scanner scan = new Scanner(System.in);
String barcode = scan.nextLine();
Otherwise just pass your barcode to main
method args.
Upvotes: 7