ISO15693(NfcV)/ Tag-it HF-I命令抛出标记丢失异常

时间:2015-04-27 18:17:32

标签: android tags nfc rfid iso-15693

当我尝试收发NFC-V Tag-it HF-I Plus Inlay标签的命令时,我得到大多数命令的TagLostException。

从链接中我经历过此异常可能是由不正确的命令引起的。

如何为Nfc V Tag-it HF-I Plus Inlay创建正确的ISO15693命令字节[]?

数据表显示了支持的命令,但如何创建正确的命令来读取NFC-V标签?

文件中的命令是:

我试图阅读的标签是:

代码:

Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
Log.i(TAG, " tag "+tag );
if (tag != null) {
    NfcV tech = NfcV.get(tag);
    Log.i(TAG, " tech "+tech  );

    if (tech != null) {
    try {
        tech.connect();
        Log.i(TAG, " on connect" );
        byte[] data = tech.transceive(Nfcv.InventoryRequest());
        Log.i(TAG, "resp data " + data);
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < data.length; i++) {
            byte b = data[i];
            System.out.println(b);
            sb.append(String.format("%02X ", b));
        }
        System.out.println("response: " + sb.toString());
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            tech.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

我已经完成了以下内容:

修改

我尝试过的命令:

public class Nfcv {
    // texas get system info -> tag lost exception
    public static byte[] GET_SYSTEM_INFO = ReadNfcActivity.hexStringToByteArray("010A00030418002B0000");

    //read multiple blocks -> not working
    byte[] read_multiple_blocks= ReadNfcActivity.hexStringToByteArray("010C00030418002301020000");

    byte[] readSingleBlock = ReadNfcActivity.hexStringToByteArray("010B000304180020050000");

    // readUID generic command -> not working
    public static byte[] readUID = ReadNfcActivity.hexStringToByteArray("FFCA000000");

    public static  byte[] InventoryRequest(){
        //working response: 00 00 3A E5 00 04 00 00 07 E0
        // R/0 UID is E0 07 00 00 04 00 E5 3A 00 00 (reverse)
        return new byte[] { (byte) 0x24, (byte) 0x01, (byte) 0x00};
    }

    //-> not working
    private byte[] ReadSingleBlockUnadressed(byte blocknumber) {
        return new byte[] {(byte) 0x00, (byte) 0x20, blocknumber};
    }

    //-> response 03
    public static byte[] get_system_info = {0x00,(byte)0x2B};
}

1 个答案:

答案 0 :(得分:1)

Android NFC堆栈会自动处理轮询(搜索各种标签技术/协议的标签),防冲突(在一个标签技术/协议中枚举多个标签)和激活(与一个特定标签进行启动通信)。因此,您不应该自己发送用于防冲突和激活的命令。 Inventory命令就是一个这样的命令(用于发现范围内的标签)。

关于Inventory命令,通常不需要发送此命令。您将从此命令获得的所有信息都已由Android NFC API提供:

  • 您可以使用tag.getId()
  • 获取UID
  • 您可以使用tech.getDsfId()
  • 获取DSFID

此外,为了让您的应用在不同的Android设备平台(=不同的NFC堆栈)上可靠地工作,您应该始终使用寻址的命令版本(即Address_flag set和UID作为请求的一部分发送)。请参阅Android NfcV get information command returns only one byte

如果要读取/写入标记,可以使用READ_SINGLE_BLOCK和WRITE_SINGLE_BLOCK命令:

byte[] tagUid = tag.getId();  // store tag UID for use in addressed commands
int blockAddress = 0; // block address that you want to read from/write to

READ_SINGLE_BLOCK:

byte[] cmd = new byte[] {
    (byte)0x20,  // FLAGS
    (byte)0x20,  // READ_SINGLE_BLOCK
    0, 0, 0, 0, 0, 0, 0, 0,
    (byte)(blockAddress & 0x0ff)
};
System.arraycopy(tagUid, 0, cmd, 2, 8);

byte[] response = tech.transceive(cmd);

的Write_single_block:

byte[] cmd = new byte[] {
    (byte)0x60,  // FLAGS
    (byte)0x21,  // WRITE_SINGLE_BLOCK
    0, 0, 0, 0, 0, 0, 0, 0,
    (byte)(blockAddress & 0x0ff),
    ... // data block that you want to write (same length as the blocks that you read)
};
System.arraycopy(tagUid, 0, cmd, 2, 8);

byte[] response = tech.transceive(cmd);