2
votes

http://www.acs.com.hk/en/products/3/acr122u-usb-nfc-reader/

I'm using the Android library linked above, and I'm trying to read/write NFC tags. The tags will have a format I know of (probably something like JSON). I am able to run the example app and see that the reader is working and detecting NFC tags, but how do I go about actually reading or writing them? The API is a little confusing. Any help is much appreciated.

So far in my app, I've figured how to get the reader state and reader type/name, but nothing regarding the NFC tags themselves.

3

3 Answers

3
votes

You can use an instance of the Reader class (com.acs.smartcard.Reader) to communicate with the reader and NFC tags that are in range of the reader.

Depending on the version of the ACR122U, you will need either the Reader.transmit() method or the Reader.control() method (in combination with the control code Reader.IOCTL_CCID_ESCAPE) to send commands to the reader. The relevant direct commands for enumerating and accessing tags are described in the Application Programming Interface manual (see here or here depending on what version of the reader you have).

Once you can access tags through the Reader object, you could implement the NFC Forum's Tag Operation specifications to interact with NFC tags.

0
votes

Other than the SDK provided by the vender ACS, you can try Libnfc which is a open source low level NFC SDK with LGPL license. You can build application upon the it.

Libnfc support ACR122U on both Linux and Windows.

0
votes

It doesn't work either. responseLength is always 0. It should not be. That command is absolutely correct Read Card ID command: {(byte)0xFF, (byte)0xCA, (byte)0x00, (byte)0x00, (byte)0x04 and it works perfectly in Windows Java Example with the same ACR122 usb reader:

// Transmit APDU
byte[] command =  {(byte)0xFF, (byte)0xCA, (byte)0x00, (byte)0x00, (byte)0x04};           
byte[] response = new byte[100];
int responseLength = 0;

try {
    responseLength = mReader.transmit(0, command, command.length, response,   response.length);
} catch (ReaderException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

TextView tv = (TextView)findViewById(R.id.main_text_view_response);
tv.setText( "resp: "+Integer.toString(responseLength) + ": "+ Integer.toString( response[0] ) );