简体   繁体   中英

Barcode print in java while barcode scanner scans

I want to read the barcode and print it in a console in a simple java program as soon as the barcode scans on top of any barcode. Is there any way?

final Scanner scanner;

    try 
    {
        scanner = new Scanner();

        try {
            scanner.release();
            scanner.close();
        } catch (Exception e) {

        }

        scanner.open("MotorolaScannerUSB");

        scanner.claim(100);
        scanner.setDeviceEnabled(true);
        scanner.setDataEventEnabled(true);

        scanner.addDataListener(new DataListener() 
        {
            public void dataOccurred(DataEvent arg0) {
                Scanner scn = (Scanner) arg0.getSource();

                if (scn.equals(scanner)) {                      
                    try {
                        scanner.claim(100);
                        System.out.println(new String(scanner.getScanData()));
                        scanner.claim(100);
                        scanner.setDeviceEnabled(true);
                        scanner.setDataEventEnabled(true);
                    } catch (JposException e) {
                        e.printStackTrace();
                    }
                }
            }
        });
    }
    catch (Exception e) {
        System.err.println("error");
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM