Search in sources :

Example 6 with TerminalFactory

use of javax.smartcardio.TerminalFactory in project open-ecard by ecsec.

the class PCSCTest method connect.

private void connect() {
    try {
        // File libPcscLite = new File("/usr/lib/libpcsclite.so.1");
        // if (libPcscLite.exists()) {
        // System.setProperty("sun.security.smartcardio.library", libPcscLite.getAbsolutePath());
        // }
        TerminalFactory t = TerminalFactory.getInstance("PC/SCs", null);
        // TerminalFactory t = TerminalFactory.getDefault();
        CardTerminals c = t.terminals();
        logger.info("Card terminals: {}", c.list().size());
        List terminals = c.list();
        if (terminals.isEmpty()) {
            logger.info("No presend cards!");
        } else {
            for (int i = 0; i < terminals.size(); i++) {
                CardTerminal ct = (CardTerminal) terminals.get(i);
                if (ct.isCardPresent()) {
                    Card card = ct.connect("*");
                    connection = card.getBasicChannel();
                    logger.info("Card found at card terminal " + i + ": ", card.toString());
                }
            }
        }
    } catch (Exception ex) {
        logger.error(ex.getMessage(), ex);
    }
}
Also used : TerminalFactory(javax.smartcardio.TerminalFactory) CardTerminals(javax.smartcardio.CardTerminals) List(java.util.List) CardTerminal(javax.smartcardio.CardTerminal) CardException(javax.smartcardio.CardException) Card(javax.smartcardio.Card)

Aggregations

TerminalFactory (javax.smartcardio.TerminalFactory)6 CardTerminal (javax.smartcardio.CardTerminal)5 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 Card (javax.smartcardio.Card)2 CardTerminals (javax.smartcardio.CardTerminals)2 IOException (java.io.IOException)1 List (java.util.List)1 CardException (javax.smartcardio.CardException)1