2

我尝试将 ACR122 集成到我的 android 应用程序中。我正在使用ACS 提供的 ANDROID 库( http://www.acs.com.hk/en/products/3/acr122u-usb-nfc-reader/ )。

一切正常,我可以检测到卡的存在,但我想提取卡的 UID/ID。有人知道这样做的功能吗?

你有这种集成的例子吗?

4

2 回答 2

7

如果是 Mifare 卡,您需要将此 APDU 字节数组发送到卡:(byte) 0xFF, (byte) 0xCA, (byte) 0x00, (byte) 0x00, (byte) 0x00. 我不确定 ACR122 API,但可能您需要将此 APDU 包装到特定的 API 方法中,例如传输()

更新

示例代码:

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

Readercom.acs.smartcard.Reader对象并且slotNum是插槽号。我不确定如何找到它,因为我没有要测试的 ACR。但是如果你告诉你能够与读者建立基本的通信,你可能知道 slotNum。

于 2015-04-23T10:03:27.173 回答
0

为了防止在尝试读取 UID 时出现此错误:

com.acs.smartcard.InvalidDeviceStateException:当前状态不等于特定。

这应该是:

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);
}
于 2021-03-01T18:54:11.067 回答