8

I have installed a bar-code scanner from Datalogic, with the goal of reading the bar-code into a java textfield. However, when I scan the bar code in Swing, the resulting text is garbage. I cannot use this. On standalone java.awt.TextField is works fine, but when I integrate this into my code, it also produces garbage non-mappable characters.

Don't know if I'll need a specific driver for JAVA, I have tried converting the string from UTF-8 to ISO-88... to no avail.

Been looking at this since 2 days in-vain.

Any help will be greatly appreciated.

Thanks

-innocent

user3524961
  • 83
  • 1
  • 3
  • 4
    Most barcode scanners simulate a keyboard -- as far as Java is concerned, it should act just like typing text. But scanners are typically also configurable into different modes, which may involve additional control characters that might mess up the text. Does your scanner work properly scanning into a text document? Does the scanner have any configuration options that might matter? What exact model is the scanner? – Russell Zahniser Apr 11 '14 at 18:55
  • 1
    Also, for debugging, try adding a key listener on the field that just prints out all the `keyTyped` characters (and perhaps the key press and release keycodes as well). You can probably identify the offending keystroke(s) and map them to a do-nothing action so they don't output as text. – Russell Zahniser Apr 11 '14 at 18:59
  • 2
    Thanks Into a non swing textfield, yes. However, when I integrated this into my main program, it bugged. I have added a KeyListener, to capture the text as it is typed, but this text is also garbled. I am still debugging this further. The scanner is Datalogic QW2100. – user3524961 Apr 13 '14 at 11:19
  • [This](http://stackoverflow.com/questions/13115704/java-get-barcode-informaton-from-barcode-scanner?rq=1) may be of help – QGA May 23 '14 at 14:28
  • Did you solve it yet? – David Bullock Jun 05 '14 at 01:38
  • What format is the barcode ? some contain nonprinting characters. – Tim Williscroft Jun 07 '14 at 22:47
  • Open a text editor that will display non-printable characters and scan the bar code on your scanner to verify what is being returned. Then compare to what you are getting in your swing applicaton. – Shane Wealti Jun 10 '14 at 13:04
  • Turns out the Keyboard language on the machine has to match that for the scanner. There was a mismatch in my case. However, even with the mismatch, the scanner would read on the command prompt. Only in a JAVA program did this have an effect. So actually not fixed. – user3524961 Jun 11 '14 at 09:53

2 Answers2

1

try resetting the scanner to remove all spurios characters/codes that might have been set up; i.e. according to the reference guide the scanner will send by default the barcode id for gs1-128 codes as an escape sequence, which might cause some trouble for swing

download the product reference guide from http://www.datalogic.com/eng/quickscan-i-lite-qw2100-pd-163.html

scan the barcode to enter programming mode

go to the relevant section and scan the codes to remove all preambles and to remove the aim label for all codes

you can also try the different types of keyboard emulation and codepage.

Lorenzo Boccaccia
  • 6,041
  • 2
  • 19
  • 29
0

There is a problem with KeyEvents coming from a barcode scanner using ALT + NumPad method. Java generates KeyTyped events with random outputs when ALT key is pressed. The problem exists in the current versions of Java 7 and Java 8 JRE (I have 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 the 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;
    }
}
JHead
  • 356
  • 2
  • 12
  • "i think" please give facts – tod Sep 21 '14 at 12:10
  • 1
    Thanks, tod, I have corrected the description. Anyway, barcode scanning is impossible in ALT + NumPad mode without this hack, I have been searching the solution for 3 years! This bug caused a lot of loss of income for me. I can't understand how can be that a so serious and basic problem still not solved in Java. – JHead Oct 10 '14 at 11:57
  • because if you need arbitrary extended ascii data you need to read from the serial port directly – Lorenzo Boccaccia Oct 20 '15 at 08:03