我收到以下代码的"标签丢失"异常。但是,尽管存在异常,数据仍会成功写入。为什么即使抛出异常,数据也能成功写入?
nfc.connect();
byte[] arrByt = new byte[7];
arrByt[0] = 0x01; //Command Flag 0x02 works fine
arrByt[1] = 0x21;
arrByt[2] = 0x06;
arrByt[3] = 0x00;
arrByt[4] = 0x00;
arrByt[5] = 0x00;
arrByt[6] = 0x00;
byte[] response = nfc.transceive(arrByt);
我的NFC芯片
Type V (ISO/IEC 15693 / Vicinity), Tag Type SL2 ICS2001 (ICODE SLI), Manufacturer NXP Semiconductors (Germany)
这里谈了但没有结果:(
当 NfcV 标签返回非成功代码时,android 的 NFC 堆栈假定它是一个异常,并抛出"标签丢失"。
要避免此异常,您可以使用命令0x02,正确的字节数组变为:
arrByte = {0x02, 0x21, 0x06, 0x00, 0x00, 0x00, 0x00};其中0x02是标志命令,0x21是写入单个块命令,0x06是块号,其余是 4 字节的数据。希望这会有所帮助。