2

I try to integrate an ACR122 to my android app. I'm using the ANDROID Library (http://www.acs.com.hk/en/products/3/acr122u-usb-nfc-reader/) available from ACS.

Everything work, I can detect the presence of a card but I want to extract the UID/ID of the card. Someone know the function to do that?

Do you have an example of this type of integration?

Michael Roland
  • 39,663
  • 10
  • 99
  • 206
kh4ZE
  • 21
  • 1
  • 2

2 Answers2

7

In case of Mifare card you need to send this APDU byte array to the card: (byte) 0xFF, (byte) 0xCA, (byte) 0x00, (byte) 0x00, (byte) 0x00 . I'm not sure about ACR122 API but probably you need to wrap this APDU into specific API method like transmit()

UPDATE

Sample code:

 byte[] command = new byte[] { (byte) 0xFF, (byte) 0xCA, (byte) 0x00, (byte) 0x00, (byte) 0x00 };
 byte[] response = new byte[300];
 int responseLength;
 responseLength = reader.transmit(slotNum, command, command.length, response,response.length);
 System.out.println(new String(response));

Reader is com.acs.smartcard.Reader object and slotNum is a the slot number. I’m not sure how to find it because I don’t have ACR to test. But if you told that you was able to establish basic communication with reader probably you know slotNum.

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
Andrey Sabitov
  • 454
  • 2
  • 5
  • 1
    When I use that syntax, it throws "Com.Acs.Smartcard.InvalidDeviceStateException: The current state is not equal to specific." Is there another step that is needed with the ACR122 API? – Chris Miller May 23 '16 at 19:39
  • @ChrisMiller I am getting the very same error. Did you ever resolve this? – BradBeighton Mar 10 '20 at 16:21
  • 2
    @BradBeighton I guess you need to do some init first: reader.power(slotNum, Reader.CARD_WARM_RESET); reader.setProtocol(slotNum, Reader.PROTOCOL_T0 | Reader.PROTOCOL_T1); – Andrey Sabitov Mar 11 '20 at 07:40
  • Hi @AndreySabitov you are correct you have to do both of those first. This is what worked for me: mReader.power(0, Reader.CARD_WARM_RESET); mReader.setProtocol(0, Reader.PROTOCOL_T0 | Reader.PROTOCOL_T1); – BradBeighton Mar 11 '20 at 17:00
0

In order to prevent this error when trying to read the UID:

com.acs.smartcard.InvalidDeviceStateException: The current state is not equal to specific.

This should rather be:

int slotNum = 0;
byte[] payload = new byte[] { (byte) 0xFF, (byte) 0xCA, (byte) 0x00, (byte) 0x00, (byte) 0x00 };
byte[] response = new byte[7]; // 7 bytes + 90 00 (9 bytes)
try {
    reader.power(slotNum, Reader.CARD_WARM_RESET);
    reader.setProtocol(slotNum, Reader.PROTOCOL_T0 | Reader.PROTOCOL_T1);
    reader.transmit(slotNum, payload, payload.length, response, response.length);
    logBuffer(response, response.length);
} catch (ReaderException e) {
    Log.e(LOG_TAG, e.getMessage(), e);
}
Martin Zeitler
  • 1
  • 19
  • 155
  • 216