3

I have a little problem with my program. For the first time as plugging the reader everything is in order, the program finds reader, but when, during the program, I disconnect the reader, and then plug it in again, and then run search again, the program is not able to find the reader. I have only CardException with message: list() failed

Anyone know how to fix it?

    TerminalFactory factory = TerminalFactory.getDefault();
    System.out.println(factory);
    List<CardTerminal> terminals = new ArrayList<CardTerminal>();
    if (factory == null) {
        return terminals;
    }
    try {
        terminals = factory.terminals().list();
    } catch (CardException e) {
        System.out.println(e.getMessage());
    }

I tried also this:

    try {
        factory = TerminalFactory.getInstance("PC/SC", null, new jnasmartcardio.Smartcardio());
    } catch (NoSuchAlgorithmException e1) {
        e1.printStackTrace();
    }

Thx for help.

SHambit
  • 31
  • 3
  • See http://stackoverflow.com/questions/16921785/smartcard-terminal-removal-scard-e-no-service-cardexception/ –  Feb 04 '16 at 14:44

1 Answers1

0

Without not knowing how you use the snippet of the code, do read about jnasmartcardio and the lifetime of the context. Windows kills the resource manager (thus invalidates the handle) after last reader is disconnected.

Martin Paljak
  • 4,119
  • 18
  • 20
  • I do it in a loop with Sleep for 1500 ms. Is it possible to somehow remedy this without using jnasmartcardio? It happens only on Windows 10, Windows 8.1 and Windows 8. How can I manually reset an object TerminalFactory to get new list with devices connected to computer? – SHambit Jan 24 '16 at 14:41