0

只要条码扫描到任何条码的顶部,我就想读取条码并将其打印在一个简单的 Java 程序中的控制台中。有什么办法吗?

4

1 回答 1

-1
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");
    }
于 2013-03-12T16:17:24.573 回答