【问题标题】:Write Multiple Blocks command failed over NfcV写入多个块命令在 NfcV 上失败
【发布时间】:2017-04-09 10:46:39
【问题描述】:

我正在尝试通过NfcV 对象使用 WRITE MULTIPLE BLOCKS 命令将一些数据写入 NXP ICODE SLIX SL2S2002 标签 (ISO 15693):

private void writeTagData(Tag tag) throws Exception {
    int offset = 0;
    int blocks = 19;

    String _writedata = "1hello34567850000071234561815064150220161603201016022018112233445552031033";
    byte[] data = _writedata.getBytes(StandardCharsets.UTF_8);
    data = Arrays.copyOfRange(data, 0, 4 * blocks );

    byte[] id = tag.getId();
    boolean techFound = false;
    for (String tech : tag.getTechList()) {
        if (tech.equals(NfcV.class.getName())) {
            techFound = true;
            NfcV nfcvTag = NfcV.get(tag);
            try {
                nfcvTag.connect();
            } catch (IOException e) {
                Toast.makeText(this, "IO Exception", Toast.LENGTH_LONG).show();
                return;
            }
            try {
                byte[] cmd = new byte[] {
                        (byte)0x20,
                        (byte)0x24,
                        (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
                        (byte)(offset & 0x0ff),
                        (byte)((blocks - 1) & 0x0ff)
                };
                System.arraycopy(id, 0, cmd, 2, 8);

                byte[] cmd_plus_data = new byte[88];
                System.arraycopy(cmd, 0, cmd_plus_data, 0, cmd.length);
                System.arraycopy(data, 0, cmd_plus_data, 12, data.length);

                byte[] response = nfcvTag.transceive(cmd_plus_data);
                String strResponse = Common.toHexString(response);
            } catch (IOException e) {
                Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
                return;
            }

            try {
                nfcvTag.close();
            } catch (IOException e) {
                Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
                return;
            }
        }
    }
}

transceive(...) 方法的响应是010f(表示“未知错误”)。以前,我可以使用命令 READ MULTIPLE BLOCKS 从同一个标签成功读取数据。

我尝试在NfcV 对象上调用getMaxTransceiveLength(),其值为253。

【问题讨论】:

  • 您要写入哪个特定标签产品?鉴于您在之前的帖子中指定了标签 UID 值 e004015057da807b,我猜它是 NXP ICODE SLIX SL2S2xx2,对吧?
  • NXP ICODE SLIX SL2S2002

标签: android tags nfc rfid iso-15693


【解决方案1】:

ISO/IEC 15693 将 WRITE MULTIPLE BLOCKS 命令定义为可选命令。由标签芯片(或者实际上是它的制造商)来实现这个命令。

在您的情况下,NXP ICODE SLIX SL2S2xx2(就像所有(大多数?)ICODE SLI/SLIX 标签一样)不支持 WRITE MULTIPLE BLOCKS 命令。因此,标签返回错误代码 0x0F。 ICODE SLIX SL2S2xx2 数据表定义在不支持命令的情况下返回此错误代码。

相反,SL2S2xx2 支持 WRITE SINGLE BLOCK (0x21) 命令。您可以在循环中使用该命令来写入所有数据:

byte[] cmd = new byte[] {
        /* FLAGS   */ (byte)0x20,
        /* COMMAND */ (byte)0x21,
        /* UID     */ (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
        /* OFFSET  */ (byte)0x00,
        /* DATA    */ (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00
};
System.arraycopy(id, 0, cmd, 2, 8);

for (int i = 0; i < blocks; ++i) {
    cmd[10] = (byte)((offset + i) & 0x0ff);
    System.arraycopy(data, 4 * i, cmd, 11, 4);

    byte[] response = nfcvTag.transceive(cmd);
}

【讨论】:

  • 这真是太好了。请问NfcV指令的参考资料在哪里?
  • @Shihab 基本命令集(例如 READ/WRITE SINGLE BLOCK)在 ISO/IEC 15693 中定义,因此您可以在那里找到它们。
  • @Michael Roland 有时写多个单块会丢失连接并抛出,“java.lang.IllegalStateException:首先调用 connect()!” .这是相当随机的,我的意思是不在固定街区。在我的情况下,每次写入/读取都会写入超过 12 个数据块。是否建议为尽可能多的块调用标签连接 -> 编写单个块 -> 关闭标签。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-11-14
  • 2013-10-07
  • 1970-01-01
  • 2013-11-16
  • 2015-12-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多