Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8353495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:16:46+00:00 2026-06-09T09:16:46+00:00

an application I am working on requires to detect, as quick as possible (in

  • 0

an application I am working on requires to detect, as quick as possible (in 500 ms maximum), that a card is removed from the field.

Here is what I did to test the time needed to detect that absence of the card:

public static long timeToGetCardAbsent(int version) throws CardException{
    TerminalFactory factory = TerminalFactory.getDefault();

    CardTerminals terminalList = factory.terminals();
    CardTerminal ct = terminalList.list().get(0);

    long connectTime = 0, disconnectTime = 0;

    ct.waitForCardPresent(0);
    connectTime = new Date().getTime();

    ct.waitForCardAbsent(0);
    disconnectTime = new Date().getTime();

    return disconnectTime - connectTime;
}

When the program is running, I tap a (DESFire) contactless card on the reader and remove it immediatly.

Here are the outputs:

1437
1437
1438
1437
1422

I means that the reader (or the program?) needs almost 1.5 seconds to detect that the card is absent, which too long time for me.

Is there a way to speed up this detection? I am currently using javax.smartcardio, would I get better results with another library? I actually don’t know what else I could use, do you have leads?

Thanks,
GChabot

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T09:16:47+00:00Added an answer on June 9, 2026 at 9:16 am

    I actually managed to improve the detection time a lot today. I was looking at that web page from “NFC Wizard” and noticed that they were very fast at detecting my card removal. This javascript web page communicates with the reader through a Java applet, so it really uses nothing more than I have.

    SpringCard, the creators of NFC Wizard, actually provides complete documentation and even source code for a similar application at that page, under Other resources > Java and “SpringCard PC/SC SDK (ZIP archive)”.

    While browsing their code, I noticed that after performing operations on the card, the use the card.disconnect(false); function (I had tried to use card.disconnect(true); but had the same results as before…bad luck).

    So here is now what I do :

    import java.util.Date;
    import javax.smartcardio.*;
    
    public class NewMethod {
        private long connectTime = -1;
        private long disconnectTime = -1;
    
        private TerminalFactory factory;
        private CardTerminals terminalList;
        private CardTerminal ct;
    
        public NewMethod() throws CardException{
            factory = TerminalFactory.getDefault();
    
            terminalList = factory.terminals();
            ct = terminalList.list().get(0);
        }
    
        public long waitForCardPresent(){
            try {
                ct.waitForCardPresent(0);
            } catch (CardException e) { }
            return new Date().getTime();
        }
    
        public long waitForCardAbsent(){
            while(true){
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e1) { }
    
                try{
                    ct.connect("*").disconnect(false);
                }
                catch(Exception e) {
                    return new Date().getTime();
                }
            }
        }
    
        public void run(){
            while(true){
                connectTime = waitForCardPresent();
                disconnectTime = waitForCardAbsent();
                System.out.println((disconnectTime-connectTime));
            }
        }
    
        public static void main(String[] args){
            NewMethod nm;
            try {
                nm = new NewMethod();
                nm.run();
            } catch (CardException e) {
                e.printStackTrace();
            }
        }
    }
    

    (The thread part is optional but I got the same results with or without it so I preferred to save a bit of processor consumption)

    Here are the times I got with the threaded version: 531, 437, 656, 657, 735, 657, 547, 844, 15, 766, 859, 563, 765, 562, 422, 437, 563, 562, 562, 672, 672, 16, 547, 546, 672, 15, 344
    and here with the unthreaded version: 984, 547, 796, 656, 796, 718, 656, 812, 625, 781, 813, 547, 797, 532, 407, 609, 719, 328, 469, 328, 0, 546, 625, 0, 843, 703

    We may notice that the results are quite unstable (and quite better with the threaded version actually), this might come from the way I tap the card against the reader but I believe this is not the only reason.

    It looks good enough for me now. I just hope I won’t get a too great variability when I will actually use it on my application.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on an application that requires a text field to fade in with
The iPad application I'm working on requires that the user provide a username and
Am currently working on an application that requires users to submit posts and comments
I am working on an application that requires text larger than the viewable screen
i am working on a web application that now requires a CMS. Could you
I'm working on an application that requires support for forward locking of media files
I'm working on an application that requires a server to do most of the
I am currently working on a GWT application that requires report printing. The use
I have an application I'm currently working on that requires Administrators to be able
I am working on an android application that requires multiple views which will overlap

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.