我尝试将ACR122集成到我的安卓应用程序中。我正在使用ANDROID库(
http://www.acs.com.hk/en/products/3/acr122u-usb-nfc-reader/
)。
一切正常,我可以检测卡的存在,但我想提取卡的UID/ID。有人知道这样做的功能吗?
您有这种类型的集成的示例吗?
发布于 2015-04-23 18:03:27
如果是Mifare卡,您需要将此APDU字节数组发送到卡:
..。我不确定APDU,但您可能需要将此ACR122封装到特定的API方法中,如transmit()
更新
示例代码:
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));是
对象和
是插槽编号。我不确定如何找到它,因为我没有ACR要测试。但是,如果你告诉我你能够与读者建立基本的交流,你可能就知道slotNum了。
发布于 2021-03-02 02:54:11
为了防止在尝试读取UID时出现此错误:
com.acs.smartcard.InvalidDeviceStateException:当前状态不等于specific。
这应该是:
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);
}https://stackoverflow.com/questions/29817873
复制相似问题