我列出了连接的卡片如下:
package smartcardio.example
import java.security.Security;
import java.util.List;
import javax.smartcardio.Card;
import javax.smartcardio.CardTerminal;
import javax.smartcardio.CardTerminals;
import javax.smartcardio.CardTerminals.State;
import javax.smartcardio.TerminalFactory;
public class ConnectExample {
public static void main(String[] args) {
try {
Security.insertProviderAt(new SmartcardioProvider(), 1);
TerminalFactory factory = TerminalFactory.getDefault();
CardTerminals terminals = factory.terminals();
while (System.in.available() == 0) {
List<CardTerminal> list = terminals.list(State.CARD_PRESENT);
if (list.isEmpty()) {
System.out.println("no terminals");
}
for (CardTerminal cardTerminal : list) {
Card card = cardTerminal.connect("*");
System.out.println("" + card);
card.disconnect(false);
}
if (terminals.waitForChange(100)) {
System.out.println("change detected...");
} else {
System.out.println("timeout");
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
它有效,但在第八次或第九次迭代后,我收到以下错误:
15:41:05,381 WARNING [de.intarsys.security.smartcard.pcsc] (pcsc monitor 1528) de.intarsys.security.smartcard.pcsc.PCSCStatusMonitor@155387cb error monitoring status: de.intarsys.security.smartcard.pcsc.PCSCException: {PCSCException.error.default}[SCARD_F_COMM_ERROR]
15:41:05,385 SEVERE [de.intarsys.security.smartcard.pcsc] (http-/0.0.0.0:8080-2) Failed to establish PC/SC context: de.intarsys.security.smartcard.pcsc.PCSCException: {PCSCException.error.default}[SCARD_F_COMM_ERROR]
at de.intarsys.security.smartcard.pcsc.PCSCException.checkReturnCode(PCSCException.java:106) [io-smartcard-1.0.0.jar:]
at de.intarsys.security.smartcard.pcsc.CommonPCSCContext.basicAcquire(CommonPCSCContext.java:102) [io-smartcard-1.0.0.jar:]
at de.intarsys.security.smartcard.pcsc.CommonPCSCContext.acquire(CommonPCSCContext.java:89) [io-smartcard-1.0.0.jar:]
at de.intarsys.security.smartcard.pcsc.NativePCSCLib.establishContext(NativePCSCLib.java:45) [io-smartcard-1.0.0.jar:]
at de.intarsys.security.smartcard.pcsc.NativePCSCContextFactory.establishContext(NativePCSCContextFactory.java:82) [io-smartcard-1.0.0.jar:]
at de.intarsys.security.smartcard.card.standard.StandardCardSystem.pcscStart(StandardCardSystem.java:106) [io-smartcard-1.0.0.jar:]
at de.intarsys.security.smartcard.card.standard.StandardCardSystem.updateCardTerminals(StandardCardSystem.java:133) [io-smartcard-1.0.0.jar:]
at de.intarsys.security.smartcard.card.CommonCardSystem.updateCardTerminals(CommonCardSystem.java:220) [io-smartcard-1.0.0.jar:]
at de.intarsys.security.smartcard.card.CommonCardSystem.getCardTerminals(CommonCardSystem.java:157) [io-smartcard-1.0.0.jar:]
at de.intarsys.security.smartcard.card.CardSystemMonitor.start(CardSystemMonitor.java:404) [io-smartcard-1.0.0.jar:]
at de.intarsys.security.smartcard.smartcardio.CardTerminalsImpl.waitForChange(CardTerminalsImpl.java:241) [io-smartcard-1.0.0.jar:]
(io-smartcard-1.0.0.jar,这是我的.jar打包io-smartcard库)
我在RHEL 7上运行此代码。
有什么想法可以解决这个问题吗? 谢谢!