ISO15693(NfcV)/Tag-it HF-I命令抛出标签丢失异常 [英] ISO15693 (NfcV) / Tag-it HF-I commands throw tag lost exception

查看:336
本文介绍了ISO15693(NfcV)/Tag-it HF-I命令抛出标签丢失异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试收发NFC-V Tag-it HF-I Plus嵌入式标签的命令时,对于大多数命令,我都会收到TagLostException.

When I try to transceive commands for NFC-V Tag-it HF-I Plus Inlay tag I get a TagLostException for most of the commands.

在我经历过此异常的链接中,可能是由于命令错误所致.

From the links I have gone through this exception may be caused by incorrect commands.

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

How can I create correct ISO15693 command byte[] for Nfc V Tag-it HF-I Plus Inlay?

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

The datasheet shows the supported commands but how can I create correct commands to read NFC-V tags?

文档中的命令为:

我要读取的标签是:

代码:

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();
        }
    }
}

我经历了以下事情:

  • NfcV Transceive command throws tag lost exception with TI HF-I plus tag(ISO15693) in android
  • Transceive Failed on ISO15693 / Tag-it HF-I
  • Android NfcV Stay Quiet Command
  • Android NfcV (ISO 15693) tag
  • Connection error when reading Android NfcV tags

我尝试过的命令:

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};
}

推荐答案

Android NFC堆栈自动处理轮询(搜索各种标签技术/协议的标签),防冲突(一种标签技术/协议中的多个标签的枚举)并为您激活(启动与一个特定标签的通信).因此,您切勿自己发送用于防冲突和激活的命令.库存命令就是这样一种命令(用于发现范围内的标签).

The Android NFC stack automatically handles polling (searching for tags various tag technologies/protocols), anti-collision (enumeration of multiple tags within one tag technology/protocol) and activation (intitiating communication with one specific tag) for you. You should, therefore, never send commands used for anti-collision and activation yourself. The Inventory command is one such command (that is used to discover tags in range).

关于清单"命令,通常不需要发送此命令.您将从该命令获取的所有信息已经由Android NFC API提供:

With regard to the Inventory command, there is typically no need to send this command. All the information that you would get from this command is already provided by the Android NFC API:

  • 您可以使用tag.getId()获取UID.
  • 您可以使用tech.getDsfId()获取DSFID.
  • You can get the UID using tag.getId().
  • You can get the DSFID using tech.getDsfId().

此外,为使您的应用在不同的Android设备平台(=不同的NFC堆栈)上可靠运行,您应始终使用命令的寻址版本(即,Address_flag集和UID作为请求的一部分发送).请参见 Android NfcV获取信息命令仅返回一个字节.

Also, for your app to work reliable across different Android device platforms (= different NFC stacks), you should always use the addressed version of commands (i.e. Address_flag set and UID sent as part of request). See Android NfcV get information command returns only one byte.

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

If you want to read from/write to the tag, you could use the READ_SINGLE_BLOCK and WRITE_SINGLE_BLOCK commands:

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:

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:

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);

这篇关于ISO15693(NfcV)/Tag-it HF-I命令抛出标签丢失异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆