0

我正在访问帮助从 RFID 阅读器检索 RFID 标签的扫描仪。我尝试在我的周围使用一个循环,Scanner.next();但这不会做任何事情。我认为一旦我的扫描仪访问 RFID 阅读器的方法,它就会永久保留在那里。有没有办法退出 RFID 的方法,然后执行我的循环的其余部分?

//The beginning of the loop
while (!doneYet) { 
        //Just a set boolean variable that I try to use later
        Inter = false;
      //A question class that I created, obtains and displays a random question
        Test = Work.randomQuestion();
        Test.display();

      //This is where my problems seem to start, this is the RFID Readers Method.
        rfid.addTagGainListener(new TagGainListener() {
            public void tagGained(TagGainEvent oe) {
                Temp = oe.getValue();
                if (Test.getRFIDTag().equals(Temp)) {
                    System.out.println("You are Correct");
                    count++;
                    System.out.println(count);
                    Inter = true;
                    System.out.println("out");
                    /*
                     * try { System.in.close(); } catch (IOException e) {
                     * TODO Auto-generated catch block e.printStackTrace();
                     * }
                     */
                } else if (!Test.getRFIDTag().equals(Temp)) {
                    System.out.println("Sorry, you are wrong");
                }
                return;
            }
        });

        // Before the RFID Opens though, this code is initiated
        rfid.openAny();
        rfid.waitForAttachment(1000);
        sc = new Scanner(System.in);

         //This is where I attempted to control the RFID Reader, but this doesn't work
        if(!Inter){
            sc.next();
        }

         //How I attempt to end the initial while loop
        if(count>10){
            doneYet = true;
        }
    }

提前感谢所有帮助。

4

1 回答 1

0

您的扫描仪实际上并没有做任何事情。sc.next()只是跳过初始空白,并返回非空白字符的第一个字符串;但它只是丢弃该字符串,从不(例如)将其传递给rfid. 据我所知,没有任何东西会触发rfid. TagGainListener(无论如何,为什么你要TagGainListener为每次循环添加一个新的?当然你只需要一个监听器?)

于 2011-12-03T18:59:56.913 回答