Reputation: 39
I am developing a Java swing app where I have to read a id card using the hid omnikey 5325 proximity reader using the smartcardio api. (windows xp os)
try {
terminals = factory.terminals().list();
System.out.println("Terminals: " + terminals);
// get the first terminal
CardTerminal terminal = terminals.get(0);
terminal.waitForCardPresent(0);
Card card = terminal.connect("T=0");
System.out.println("Card present!");
System.out.println("card: " + card);
} catch (CardException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
The code detects the reader, but when the card is inserted, the
terminal.waitForCardPresent(0)
is supposed to return, which it doesnt.
When I use the HID's own workbench, the card is detected, hence there are no issues with the card or the reader.
Upvotes: 0
Views: 914
Reputation: 93938
You are selecting a card terminal from a list using just an index. This is not the most reliable method of choosing a terminal. The reason you get the wrong terminal is that the reader contains both a contact and contactless readers, which are separate readers to the system. So you were waiting for a contact card to be inserted.
Instead it is much better to choose a card reader by name. You can get the name by using your List
of CardTerminal
s and then printing out the name (or use a diagnostics utility etc., the name is the PCSC determined name for the reader, compiled by your operating system using the reader characteristics and a sequence number).
Upvotes: 1
Reputation: 39
Solved the problem. Changing the line:
CardTerminal terminal = terminals.get(0); to CardTerminal terminal = terminals.get(1); did the trick. Guess this array starts from 1 instead of 0.
Upvotes: 0