对于某些背景,我使用In_List_Passive_Target
了 PN532 用户手册中指定的命令来检索终端字段中所有卡的 UID。我还使用 ACR122U 的伪命令FF 00 00 00 04
将这些命令发送到 PN532。
>> FF 00 00 00 04 D4 4A 01 00 # In_List_Passive_Target (1)
<< D5 4B 01 01 00 04 08 04 3E 58 A7 D1 # Response including UID (1)
>> FF 00 00 00 04 D4 4A 01 00 # In_List_Passive_Target (2)
<< D5 4B 01 01 00 04 08 04 9E 69 A7 D1 # Response including UID (2)
>> FF 00 00 00 04 D4 4A 01 00 # In_List_Passive_Target (3)
<< D5 4B 00 # No more cards in field (3)
现在我已经这样做了,我想一一选择这些。我可以通过In_Deselect
在使用完一张卡片 ( ) 后暂停它,然后使用In_List_Passive_Target
带有其 UID 的命令选择下一张卡片来做到这一点。
但是,每次我选择一张卡时,我都想知道它返回的 ATR。事实证明,使用 Java Smart Card IO API 很难做到这一点,因为终端创建的卡对象始终是同一张卡(因此返回相同的 ATR),即使我断开卡然后创建新卡也是如此。考虑到如果我通过 PN532 终端命令与卡通信,这很奇怪In_Data_Exchange
,它是正确的不同卡(不是通过 Card 对象可访问的旧卡)。我需要 ATR 能够检测它是哪种类型的卡(Mifare Classic、Desfire、Ultralight 等)
这是我为收集卡片创建的功能:
public static void getCardsInField()
{
cardList = new ArrayList<AbstractCard>();
Boolean loop = true;
// Card already connected to the terminal
byte[] firstCardUID = transmitADPUCommand(GET_ADDRESS);
MifareClassic firstCard = new MifareClassic(cardChannel, firstCardUID);
cardList.add(firstCard);
System.out.println(firstCard);
System.out.println(readable(card.getATR().getBytes()));
while(loop)
{
byte[] inDeselectResponse = transmitADPUCommand(IN_DESELECT); // Deselect current card
byte[] inListPassiveTargetsResponse = transmitADPUCommand(IN_LIST_PASSIVE_TARGETS); // Select a new card
System.out.println(">> " + readable(IN_LIST_PASSIVE_TARGETS));
System.out.println("<< " + readable(inListPassiveTargetsResponse));
// Trying to create a new card object for new card
try
{
card.disconnect(true);
card = cardTerminal.connect("*");
cardChannel = card.getBasicChannel();
}
catch (CardException e)
{
e.printStackTrace();
}
if (Arrays.equals(inListPassiveTargetsResponse, IN_LIST_PASSIVE_TARGET_RESPONSE_NO_TARGETS)) // no more targets
{
loop = false;
}
else
{
byte[] loopCardUID = extractUID(inListPassiveTargetsResponse);
MifareClassic loopCard = new MifareClassic(cardChannel, loopCardUID);
cardList.add(loopCard);
System.out.println(loopCard);
System.out.println(readable(card.getATR().getBytes())); // this should be different ATR but it is the old cards atr
}
}
}