Reading from a barcode scanner in Swing

I installed a barcode scanner from Datalogic in order to read the barcode into a java text field. However, when I look at the barcode in Swing, the resulting text is garbage. I can not use this. On standalone java.awt.TextField works fine, but when I integrate this into my code, it also creates unnecessary garbage characters.

I don’t know if I need a specific driver for JAVA, I tried to convert a string from UTF-8 to ISO-88 ... to no avail.

I looked at it from 2 days in vain.

Any help would be greatly appreciated.

thanks

-innocent

+7
java swing barcode
source share
2 answers

try resetting the scanner to remove all spurios characters / codes that could be configured; that is, according to the reference guide, the scanner will by default send the barcode identifier for gs1-128 codes as an escape sequence, which may cause some problems for swinging

Download the product manual from http://www.datalogic.com/eng/quickscan-i-lite-qw2100-pd-163.html

scan a barcode to enter programming mode

go to the appropriate section and scan the codes to remove all preambles and remove the target mark for all codes.

You can also try different types of keyboard and code page emulation.

+1
source share

There is a problem with KeyEvents coming from a barcode scanner using the ALT + NumPad method. Java generates KeyTyped events with random outputs when the ALT key is pressed. The problem exists in current versions of Java 7 and Java 8 JRE (I tested it with JRE 7u67 and JRE 8u20 on Windows 8, Windows 7 and Ubuntu 14).

My solution is to register a KeyEventDispatcher that blocks KeyEvents when the ALT method is active:

KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher( new AltBugFixKeyEventDispatcher()); public class AltBugFixKeyEventDispatcher implements KeyEventDispatcher { private int i = -1; @Override public boolean dispatchKeyEvent(KeyEvent ke) { if (ke.isAltDown()) { switch (ke.getID()) { case KeyEvent.KEY_PRESSED: if(ke.getKeyCode() == KeyEvent.VK_ALT){ i = 0; }else if(Character.isDigit(ke.getKeyChar())){ i++; }else{ i = -1; } break; case KeyEvent.KEY_RELEASED: break; case KeyEvent.KEY_TYPED: break; } if(i != -1){ return true; } } return false; } } 
0
source share

All Articles