在某些背景下,我使用了PN532用戶手冊中指定的In_List_Passive_Target
命令來檢索終端字段中所有卡的UID。我還使用僞命令FF 00 00 00 04
爲ACR122U發送這些命令到PN532。無法在使用智能卡IO時檢索第二張卡的ATR
>> 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
)來完成此操作,然後通過使用帶有UID的In_List_Passive_Target
命令選擇下一張卡片。
但是,每次我選擇一張卡時,我都想知道它返回的ATR。 Java智能卡IO API證明這很困難,因爲終端創建的卡對象始終是同一張卡(並因此返回相同的ATR),即使我斷開卡然後創建新卡也是如此。這很奇怪,因爲我通過PN532終端命令In_Data_Exchange
與卡通信,它是正確的不同卡(不是通過卡對象可訪問的舊卡)。我需要的ATR能夠檢測到它是哪種類型的卡(MIFARE經典,DESFIRE,超輕等)
下面是我收集的卡創建的函數:
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
}
}
}
我可以請你告訴我UID和ATR和ATS有什麼區別? – Abraham 2015-04-05 18:34:29