Reputation: 737
When card reader connect to card and send command, in case the time to send command and receive response is, is system notify timeout exception automatically ?
If so, What is timeout value of PC/SC ?
Or I must define that value?
Upvotes: 1
Views: 1572
Reputation: 6126
Well, there are two methods available useful to handle exceptions when there is no card available in the reader:
boolean sun.security.smartcardio.TerminalImpl.waitForCardAbsent ( long timeout ) throws CardException [virtual]
Waits until a card is absent in this terminal or the timeout expires. If the method returns due to an expired timeout, it returns false. Otherwise it return true.
If no card is present in this terminal when this method is called, it returns immediately.
Parameters: timeout if positive, block for up to timeout milliseconds; if zero, block indefinitely; must not be negative
Returns: false if the method returns due to an expired timeout, true otherwise.
Exceptions: IllegalArgumentException if timeout is negative ,CardException if the operation failed
Implements javax.smartcardio.CardTerminal.
Definition at line 136 of file TerminalImpl.java.
boolean sun.security.smartcardio.TerminalImpl.waitForCardPresent (long timeout) throws CardException [virtual]
Waits until a card is present in this terminal or the timeout expires. If the method returns due to an expired timeout, it returns false. Otherwise it return true.
If a card is present in this terminal when this method is called, it returns immediately.
Parameters: timeout if positive, block for up to timeout milliseconds; if zero, block indefinitely; must not be negative
Returns: false if the method returns due to an expired timeout, true otherwise.
Exceptions: IllegalArgumentException if timeout is negative ,CardException if the operation failed Implements javax.smartcardio.CardTerminal.
Definition at line 132 of file TerminalImpl.java.
For card's response timeout, you should first check your reader manual. some smart card readers have some additional features other than sending APDU commands to the card. This commands called "Pseudo APDU". For example I have an ACR38 contact smart card reader and I found the following in its manual:
(From here page 14)
Finally if you didn't found anything useful in your reader's manual, I think you have two options:
timeout
method in your multi-threaded java program that is executing always and calculate the time after sending each command and check to see if the response time is greater that a specific value or not. In cases that the time is greater than your specific value, it call the disconnect
method and reconnect it and then you can handle it in such a way. Check the following links, I think you can find something useful there to aim your goal:
http://www.openscdp.org/ocf/api/de/cardcontact/opencard/terminal/smartcardio/PCSCIOControl.html
http://ludovic.rousseau.free.fr/softwares/pcsc-perl/PCSC.html
http://myacr38.blogspot.com/2007/05/program.html
Upvotes: 4