Reputation: 73
My application is working properly in all aspects apart from when I wish to remove contactless card 'A', and replace it with contactless card 'B'.
Once card B is present, I run the following PCSC functions:
lResult = PCSC.SCardDisconnect(hCard, SCARD_RESET_CARD)
lResult = PCSC.SCardReleaseContext(hContext)
lMode = SCARD_SHARE_EXCLUSIVE
lProtocol = SCARD_PROTOCOL_T0
lResult = PCSC.SCardEstablishContext(SCARD_SCOPE_USER, 0, 0, hContext)
If lMode = SCARD_SHARE_DIRECT Then
lResult = PCSC.SCardConnect(hContext, ConnReaderName, lMode, 0, hCard, lActiveProtocol)
Else
lResult = PCSC.SCardConnect(hContext, ConnReaderName, lMode, lProtocol, hCard, lActiveProtocol)
End If
Despite this code disconnecting, releasing context, re-establishing context and reconnecting to the card, I seem to get an 8010000f Protocol Mismatch error. Both cards are T=0. After much testing I have discovered that the only thing which actually works is to wait for about 10 seconds of no activity after introducing contactless card B to the field, whereupon the reader's activity light flashes again, seemingly resetting the card and allowing the transaction to go ahead as normal.
Why does this happen? And is there a way that I can force that eventual reset sooner?
I did separate out the ScardDisconnect and ScardReleaseContext commands, performing them whilst Contactless Card A was still in the field, but it made no difference.
Upvotes: 1
Views: 834
Reputation: 131
Here is a possible solution:
establish a new connect in direct mode, followed by a reconnect in shared/exclusive mode, forcing a card reset or card unpower
ret = SCardConnect(hContext, readername, lMode, SCARD_PROTOCOL_T0, &hCard, &dwActiveProtocol);
if (ret == SCARD_E_PROTO_MISMATCH) {
ret = SCardConnect(hContext, readername, SCARD_SHARE_DIRECT, 0, &hCard, &dwActiveProtocol);
if (!ret) ret = SCardReconnect(hCard, lMode, SCARD_PROTOCOL_T0, SCARD_RESET_CARD, &dwActiveProtocol);
}
Upvotes: 0