android - 使用 Android 读取 NXP ICODE SLI-L 标签

标签 android nfc iso-15693

我正在尝试在我的 Android 应用程序中读取 NXP 开发的 NFC 标签。可以用 Android 读取标签:App by NXPone other正确阅读。

确切的标签类型是“ICODE SLI-L (SL2ICS50)”,RF 技术是“Type V/ISO 15693”(从这些工作应用程序中获取的数据)。内存由 2 页组成,每页有 4 个 block ,每个 block 有 4 个字节——我只想将整个数据存储在内存中。

标签必须使用 Android 的 NfcV 类处理,标签的数据表是 available here ,但很难找到任何使用 NfcV 的工作代码示例。我尝试了一些我自己根据数据表得出的结论,并尝试了来自 this PDF I found with Google 的通信样本。 , 但没有任何效果。

我的 Activity (我使用 NFC 前台调度)中的相应方法如下所示:

public void onNewIntent(Intent intent) {
    android.nfc.Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
    NfcV tech = NfcV.get(tag);
    try {
        tech.connect();
        byte[] arrByt = new byte[9];
        arrByt[0] = 0x02;
        arrByt[1] = (byte) 0xB0;
        arrByt[2] = 0x08;
        arrByt[3] = 0x00;
        arrByt[4] = 0x01;
        arrByt[5] = 0x04;
        arrByt[6] = 0x00;
        arrByt[7] = 0x02;
        arrByt[8] = 0x00;
        byte[] data = tech.transceive(arrByt);
        // Print data
        tech.close();
    } catch (IOException e) {
        // Exception handling
    }
}

当我 Handlebars 机放在标签上时,该方法被正确调用,但是 NfcV 对象的 transceive() 方法总是抛出 IOException: android .nfc.TagLostException:标签丢失。。这是我尝试过的所有字节数组的结果(上面的不太可能是正确的,但在过去的几天里,我尝试了一堆其他的结果,它们都导致了相同的行为。

根据我在 Internet 上阅读的内容,我得出的结论是,错误的发生是因为我向标签发送了错误的命令——但我就是想不出正确的命令。有什么想法吗?

最佳答案

ISO 15693 定义了不同的读取命令,制造商也可以定义专有的读取命令。所有 ICODE 标签都支持 ISO 15693 单 block 读取命令。您可以按如下方式发送:

public static void processNfcIntent(Intent intent){
    Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
    if(tag != null){
      // set up read command buffer
      byte blockNo = 0; // block address
      byte[] readCmd = new byte[3 + id.length];
      readCmd[0] = 0x20; // set "address" flag (only send command to this tag)
      readCmd[1] = 0x20; // ISO 15693 Single Block Read command byte
      byte[] id = tag.getId();
      System.arraycopy(id, 0, readCmd, 2, id.length); // copy ID
      readCmd[2 + id.length] = blockNo; // 1 byte payload: block address

      NfcV tech = NfcV.get(tag);
      if (tech != null) {
        // send read command
        try {
          tech.connect();
          byte[] data = tech.transceive(readCmd); 
        } catch (IOException e) {
          e.printStackTrace();
        } finally {
          try {
            tech.close();
          } catch (IOException e) {
            e.printStackTrace();
          }
        }
      }
    }
}

关于android - 使用 Android 读取 NXP ICODE SLI-L 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15689582/

相关文章:

android - 我可以模拟 NFC-V 标签吗?

android - 如何在Gradle中使用Transform API?

java - 评分值没有出现在我的 firebase 数据库中

android - 在没有 NFC 手机的情况下创建 NFC "Tag"对象?

android - 为什么Android和IOS11无法通过NFC通信

android - 如何使用 NFC 标签关闭飞行模式?

android - 部分 NFC 手机无法读取标签

Android NFC 读取 ISO15693 RFID 标签

android - 如何从 fragment 中获取 getSupportFragmentManager()

android - 设置android :extractNativeLibs=false to reduce app size