Example usage for javax.smartcardio CardTerminal waitForCardPresent

List of usage examples for javax.smartcardio CardTerminal waitForCardPresent

Introduction

In this page you can find the example usage for javax.smartcardio CardTerminal waitForCardPresent.

Prototype

public abstract boolean waitForCardPresent(long timeout) throws CardException;

Source Link

Document

Waits until a card is present in this terminal or the timeout expires.

Usage

From source file:davmail.util.ClientCertificateTest.java

public void testCardReaders() throws CardException {
    for (CardTerminal terminal : TerminalFactory.getDefault().terminals().list()) {
        System.out.println("Card terminal: " + terminal.getName() + " "
                + (terminal.isCardPresent() ? "Card present" : "No card"));
        terminal.waitForCardPresent(10);
        if (terminal.isCardPresent()) {
            Card c = null;/*from  w ww  .j  a v  a2s .c o  m*/
            try {
                c = terminal.connect("T=0");
            } catch (Exception e) {
                // failover
                c = terminal.connect("T=1");
            }

            ATR atr = c.getATR();

            byte[] bytes = atr.getBytes();
            System.out.print("card:");

            for (byte b : bytes) {
                System.out.print(" " + Integer.toHexString(b & 0xff));
            }
            System.out.println();

        }
    }
}