我是RFID技术编程的新手。我能够使用连接到我的Raspberry Pi的ITEAD PN532 NFC模块读取某些RFID卡的ID;这是我使用的代码:
B
正如我所说,这适用于某些卡片。但现在我想能够将数据写入EMPTY(新)RFID卡(Mifare 8k):要做到这一点,我认为第一步是连接到卡然后发送正确的APDU命令;但刷我新的空白卡时,connect()方法给了我一个例外:
public static void main(String[] args) {
try {
//initialization code
TerminalFactory factory = TerminalFactory.getDefault();
CardTerminals terminals = factory.terminals();
List<CardTerminal> list = terminals.list();
CardTerminal cardTerminal = list.get(0);
//Card processing loop
System.out.println("Terminal name : " + cardTerminal.getName());
System.out.println("Card processing loop...");
while(true){
cardTerminal.waitForCardPresent(0);
handleCard(cardTerminal);
cardTerminal.waitForCardAbsent(0);
}
} catch (Exception e) {
e.printStackTrace();
}
}
private static void handleCard(CardTerminal cardTerminal) throws CardException {
final byte[] readUID = new byte[]{(byte) 0xFF, (byte) 0xCA, 0, 0, 0};
Card card = cardTerminal.connect("*");
CardChannel channel = card.getBasicChannel();
CommandAPDU command = new CommandAPDU(readUID);
ResponseAPDU response = channel.transmit(command);
byte[] uiBytes = response.getData();
String uid = bytesToString(uiBytes);
System.out.println(uid);
}
private static String bytesToString(byte[] uiBytes) {
StringBuilder result = new StringBuilder();
for(byte b:uiBytes){
result.append(String.format("%02x", b));
}
return result.toString();
}
我不确定,但我想这是因为卡片是空白的(我不知道,因为我提到我是全新的并且不太了解这一点)。
我有什么遗失的东西吗? 它是什么,我该如何处理? 你能指导我吗? 请帮忙