如何退出扫描器类以执行循环的其余部分?

发布于 2024-12-19 12:05:40 字数 1829 浏览 4 评论 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;
        }
    }

预先感谢您的所有帮助。

I am accessing a Scanner that helps retrieve RFID Tags from an RFID Reader. I tried using a loop around my Scanner.next(); but that wouldn't do anything. I think that once my Scanner accesses the RFID Reader's method, that it just permanently stays in there. Is there any way to exit the method for the RFID and then perform the rest of my loop?

//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;
        }
    }

Thanks in advance for all of the help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嗼ふ静 2024-12-26 12:05:40

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

Your scanner doesn't actually do anything. sc.next() just skips initial whitespace, and returns the first string of non-whitespace characters; but it just discards that string, never (for example) passing it to rfid. As far as I can see, nothing ever triggers rfid's TagGainListener. (And why do you add a new TagGainListener for each pass through the loop, anyway? Surely you only need one listener?)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文