我試圖使用SECTOR_SELECT讀寫指定扇區,但是在通過MifareUltralight.transceive()
發送命令的第二部分時得到TagLostException
。我如何選擇和操縱部門?MifareUltralight:扇區選擇原因TagLostException
我正在使用Android Nexus 6(6.0.1)向NXP NTAG(NT3H1201)發送命令並從中獲取數據。我可以使用帶收發器的GET_VERSION命令(60h)(通過NfcA
和MifareUltralight
)。
我使用選擇一個部門的方法:
public void selectSector(byte sector, MifareUltralight mifareUltralight) throws IOException {
if (mifareUltralight.isConnected()) {
mifareUltralight.close();
}
// SECTOR_SELECT command (see nxp p. 46)
byte[] sectorSelectCmdPacket1 = new byte[2];
byte[] sectorSelectCmdPacket2 = new byte[4];
sectorSelectCmdPacket1[0] = (byte) 0xc2; // Sector select command
sectorSelectCmdPacket1[1] = (byte) 0xff;
sectorSelectCmdPacket2[0] = sector; // Memory sector to be selected; 1 for I2C 2k version
sectorSelectCmdPacket2[1] = (byte) 0x00;
sectorSelectCmdPacket2[2] = (byte) 0x00;
sectorSelectCmdPacket2[3] = (byte) 0x00;
mifareUltralight.connect();
try {
// ACK = 0A
byte[] sectorSelectResp1 = mifareUltralight.transceive(sectorSelectCmdPacket1);
Log.w(TAG, bytesToHex(sectorSelectResp1));
} catch (IOException e) {
Log.w(TAG, "selectSector: there was an exception while sending first sector select command");
e.printStackTrace();
}
try {
mifareUltralight.transceive(sectorSelectCmdPacket2);
Log.w(TAG, "Second sector select command sent");
} catch (IOException e) {
Log.w(TAG, "selectSector: there was an exception while sending second sector select command");
e.printStackTrace();
}
mifareUltralight.close();
}
當我打電話selectSector方法,第一收發完成,但第二次卻沒有,導致錯誤
機器人。 nfc.TagLostException:標記丟失。
如何在沒有得到TagLostException
的情況下選擇和操作扇區?
這是非常有用的信息。謝謝,邁克爾! – fipoceilz7
你會推薦哪些資源來學習這方面的知識? – fipoceilz7
@ fipoceilz7我沒有意識到任何有用的公共資源(除了自己試驗和挖掘Android NFC堆棧)。我們確實提供培訓;-) –