简体   繁体   中英

NFC with ACR122U and Android

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.

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.

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] ) );

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM