简体   繁体   English

NFC与ACR122U和Android

[英]NFC with ACR122U and Android

http://www.acs.com.hk/en/products/3/acr122u-usb-nfc-reader/ 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. 我正在使用上面链接的Android库,并且正在尝试读取/写入NFC标签。 The tags will have a format I know of (probably something like JSON). 标签将具有我所知道的格式(可能类似于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? 我可以运行示例应用程序,并看到读取器正在工作并正在检测NFC标签,但是如何实际读取或编写它们呢? The API is a little confusing. 该API有点令人困惑。 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. 到目前为止,在我的应用程序中,我已经找到了如何获取读取器状态和读取器类型/名称的方法,但是与NFC标签本身无关。

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. 您可以使用Reader类的实例( com.acs.smartcard.Reader )与阅读器和阅读器范围内的NFC标签进行通信。

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. 根据ACR122U的版本,您将需要Reader.transmit()方法或Reader.control()方法(与控制代码Reader.IOCTL_CCID_ESCAPE结合使用)向阅读器发送命令。 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. 一旦可以通过Reader对象访问标签,就可以实现NFC论坛的标签操作规范以与NFC标签进行交互。

It doesn't work either. 它也不起作用。 responseLength is always 0. It should not be. responseLength始终为0。不应为0。 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: 该命令绝对是正确的读卡ID命令: {(byte)0xFF, (byte)0xCA, (byte)0x00, (byte)0x00, (byte)0x04并且在Windows Java示例中使用相同的ACR122 usb阅读器即可完美运行:

// 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. 除了供应商ACS提供的SDK外,您可以尝试Libnfc ,它是具有LGPL许可证的开源低级NFC SDK。 You can build application upon the it. 您可以在其上构建应用程序。

Libnfc support ACR122U on both Linux and Windows. Libnfc在Linux和Windows上均支持ACR122U。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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