android - ISO15693/Tag-it HF-I 收发失败

标签 android nfc rfid iso-15693

我有一些 ISO15693/Tag-it HF-I Plus 芯片,需要在上面写点东西。这些薯片是完全新鲜的,我现在读了很多 pdf 都告诉我同样的事情。但没有任何效果,而且我一直收到“收发失败”错误。

我在收发命令中发送这些数据:

Byte:  <data>
0:     0x00 // pdf says the tag understands only flag = 0x00
1:     0x21 // write single block
2-10:  ID // needs to be send for this tag, only supports addressed mode
11:    0x00 // Block ID, try to write to block 0
12-16: DATA // LSB First
17-18: CRC16 // do i need to send this? and if yes, LSB first?

我尝试了非常不同的标志和写入模式,但它们都不起作用:

Flags: 0x01, 0x02, 0x20,0x22,0x42,0x40,0x80,0x82
Modes: 0x21,0xA2 (+ Vendor Mode 0x07)

这是我的写函数:

private void write(Tag tag) throws IOException, FormatException {
if (tag == null) {
    return;
}
NfcV nfc = NfcV.get(tag);
byte[] ID = tag.getId();

nfc.connect();

Log.d(TAG, "Data: " + new String(((EmergencyApplication) getApplication()).getData()));

byte[] data = ((EmergencyApplication) getApplication()).getData();
// NfcV Tag has 64 Blocks with 4 Byte
if ((data.length / 4) > 64) {
    // ERROR HERE!
    Log.d(TAG, "too much data...");
}

for (int i = 0; i < data.length; i++) {
    byte[] arrByte = new byte[17];

    // Flags
    arrByte[0] = 0x00; // Tag only supports flags = 0
    // Command
    arrByte[1] = 0x21;
    // ID
    Log.d(TAG, "Found ID length: " + ID.length + "... ID: " + Arrays.toString(ID));
    System.arraycopy(ID, 0, arrByte, 2, 8);
    // block number
    arrByte[10] = (byte) (i);

    // data
    // TODO send LSB first...
    System.arraycopy(data, i * 4, arrByte, 11, 4);

    // CRC 16 of all command
    byte[] check = new byte[15];
    System.arraycopy(arrByte, 0, check, 0, 15);
    int crc = CRC.crc16(check);
    arrByte[15] = (byte) (crc >> 8);
    arrByte[16] = (byte) (crc & 0xFF);

    Log.d(TAG, "Writing Data: " + Arrays.toString(arrByte));

    byte[] result = nfc.transceive(arrByte);
    Log.d(TAG, "got result: " + Arrays.toString(result));
}

nfc.close();
Toast.makeText(this, "wrote to tag", Toast.LENGTH_LONG).show();

}

这是 Nexus S 的另一个错误吗?我使用 Cyanogenmod 10.1.2,所以我认为 Tag Lost Bug 已修复...我显然可以读取标签,如果我使用 NFC Tag Info App,它会显示所有 block 清晰且可写。 我阅读了这些 PDF:

http://rfidshop.com.hk/datasheet%20tag/philip%20icode%20SLI.pdf - 我的标签数据表 http://www.waazaa.org/download/fcd-15693-3.pdf - ISO15693-3 数据表 http://www.ti.com/lit/ug/scbu003a/scbu003a.pdf - Tag-it HF-I Plus 数据表

我用这里的代码测试了阅读:Reading a NXP ICODE SLI-L tag with Android - 它适用于所有 64 个 block ,但写入仍然不起作用...即使标志 = 0x20...

编辑:我现在看到卡上的 DSFID 是 0x00,这意味着对于 ISO15693-3 卡根本不可写:

If its programming is not supported by the VICC, the VICC shall respond with the value zero ('00')

这是发送0x2B时的byte[]:

                                                     DSFID \  / AFI
                                                           |  |
                                                           v  v
infoRmation: [0, 15, 120, 40, -51, -51, 119, -128, 7, -32, 0, 0, 63, 3, -117]

最佳答案

发现了一些东西,我想分享一下:

  • 不要先发送带有 LSB 的数据,似乎收发命令会在发送时自动执行此操作
  • 不要使用寻址模式,android 实现似乎有一些问题
  • 在标志中设置选项位 (0x40)。
  • 我的标签好像支持快速模式(0x02),所以你可以设置或不设置
  • 不要设置CRC16,因为它是android添加的

但最糟糕的是,标签在编译到标签编写器中时没有响应。您将得到一个 Tag is lost. 异常,但数据将写入标签!所以解决方案是忽略这个异常,也许在写入后验证数据,如果它不起作用再试一次。

我目前写的代码是这样的:

public static void write(Tag tag, byte[] data) throws IOException, FormatException,
InterruptedException {
if (tag == null) {
    return;
}
NfcV nfc = NfcV.get(tag);

nfc.connect();

Log.d(TAG, "Max Transceive Bytes: " + nfc.getMaxTransceiveLength());

// NfcV Tag has 64 Blocks with 4 Byte
if ((data.length / 4) > 64) {
    // ERROR HERE!
    Log.d(TAG, "too much data...");
}

if ((data.length % 4) != 0) {
    byte[] ndata = new byte[(data.length) + (4 - (data.length % 4))];
    Arrays.fill(ndata, (byte) 0x00);
    System.arraycopy(data, 0, ndata, 0, data.length);
    data = ndata;
}

byte[] arrByte = new byte[7];
// Flags
arrByte[0] = 0x42;
// Command
arrByte[1] = 0x21;

for (int i = 0; i < (data.length / 4); i++) {

    // block number
    arrByte[2] = (byte) (i);

    // data, DONT SEND LSB FIRST!
    arrByte[3] = data[(i * 4)];
    arrByte[4] = data[(i * 4) + 1];
    arrByte[5] = data[(i * 4) + 2];
    arrByte[6] = data[(i * 4) + 3];

    Log.d(TAG, "Writing Data to block " + i + " [" + printHexString(arrByte) + "]");
    try {
    nfc.transceive(arrByte);
    } catch (IOException e) {
    if (e.getMessage().equals("Tag was lost.")) {
        // continue, because of Tag bug
    } else {
        throw e;
    }
    }
}

nfc.close();
}

而且效果很好。 如果存在真正的错误,例如消息未被理解,您将收到 Transceive Failed 消息。

关于android - ISO15693/Tag-it HF-I 收发失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18211548/

相关文章:

android - 读取 NFC 标签上的 "payload"数据?

android - 使用 NdefMessage 写入图像

ios - 使用 iPhone 6/iOS 8 读取 NFC 标签

android - 在新的 android map api 中没有互联网连接的情况下首次启动应用程序后 map 不会绘制

android - 当我从一个选项卡单击到另一个选项卡时,如何使选项卡在 TabLayout 中不可滚动

java - 操作 Java/Android color int 的 alpha 字节

permissions - Mifare 访问条件计算

android - liquidfun 1.1.0 ndk-build 2 编译错误

java - 锁写 Mifare Ultralight C

c# - 在 C# 中将 byte 转换为 bool