Search code examples
pcsc

How to communicate with the reader using PC/SC


I'm trying to communicate with an ACS ACR122U NFC card reader using the PC/SC API on Windows (winscard.dll).

According to this document, there is a pseudo-APDU available to read the card reader firmware version: FF 00 48 00 00

With a card in the reader, I have this working: I call SCardEstablishContext(), then SCardConnectA() to get a handle, then with the handle I call SCardTransmit(). I get an answer, just as expected.

But how to do that without a card in the reader?

The above document says:

• Pseudo-APDUs can be sent through the “ACR122U PICC Interface” if the tag is already connected
• Pseudo-APDUs can be sent using “Escape Command” if the tag is not yet presented

I have no idea what that means. If I try the same method as above without a card in the reader, the SCardConnectA() call fails with an SCARD_W_REMOVED_CARD error, which means I have no handle to call SCardTransmit() with.


Solution

  • Ok, I figured it out. To be allowed to call SCardConnectA() without a card in the reader, dwShareMode must be SCARD_SHARE_DIRECT and dwPreferredProtocols must be 0.