Skip to Main Content

Java Card

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Smartcardio INSERT / REMOVE card event

796229May 7 2009 — edited Jun 17 2009
Hi all,

I am in dire need of some help, I have developed a simple Javacard applet and a smartcardio interface to communicate with it. So far I can communicate with it fine but I have no way of handling if a card is removed during/after or between a transaction or transactions.

Example of what I would like to do is to have some kind of event listener on the card terminal that would triger an event if
(1) A card is present
(2) A card is inserted
(3) A card is removed

At the minute I am doing the following:

{code
}try{
while (true) {
for ( CardTerminal terminal : getCardTerminals().list(CardTerminals.State.CARD_INSERTION)){

// Application waits until a card is inserted into any of the terminals in the CardTerminals().list

System.out.println("Card inserted into a terminal");
try {
Thread.sleep(100);
} catch (Exception e) {
System.out.print(("Error Sleep"));
}
try {
setCard(terminal.connect(" *** "));
System.out.println("Terminal connected");
} catch (Exception e) {
System.out.println("Terminal NOT connected: " + e.toString());
}
System.out.println("ATR: " + arrayToHex(((ATR) getCard().getATR()).getBytes()));
setCardChannel(card.getBasicChannel());
if (check9000(getCardChannel().transmit(SELECT_APDU))) {
System.out.println("Applet succesfully selected");
try {
getFileOutputStream().write(getDateTime().getBytes());
} catch (IOException e) {
e.printStackTrace();
}
}
else {
System.out.println("Applet not selected!");
return;
}
return;
}
}

}
catch (CardException e) {
System.out.println("Error isCardPresent()" + e.toString());
}
}
This works fine if I insert a card into the terminal, it will select my applet.

*What I am looking for is a way to control it better, and possible add some pop up JOptionPane messages as the card is inserted, removed etc....*
Can I use *waitForChange* or is there a way to run the following all at the same time waiting for any of the events and taking whatever appropriate action is required depending on the which on happens: 
CardTerminal terminal : getCardTerminals().list(CardTerminals.State.CARD_INSERTION)
CardTerminal terminal : getCardTerminals().list(CardTerminals.State.CARD_ABSENT)
CardTerminal terminal : getCardTerminals().list(CardTerminals.State.CARD_PRESENT)
CardTerminal terminal : getCardTerminals().list(CardTerminals.State.CARD_REMOVAL

Any help would be greatly accepted

Thank you in advance

Raymond                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 15 2009
Added on May 7 2009
4 comments
2,218 views