0

我目前正在尝试将几个字节写入特定块。我的读取命令工作正常,我可以使用以下代码读取我的标签的任何块:

command = new byte[]{
            (byte) 0x02, // Flags
            (byte) 0x23, // Command: Read multiple blocks
            (byte) 0x09, // First block (offset)
            (byte) 0x03  // Number of blocks // MAX READ SIZE: 32 blocks:1F
    };
byte[] data = nfcvTag.transceive(command);

当我尝试使用下面的代码编写时,我的应用程序崩溃了。

Write = new byte[]{
                (byte) 0x02, // Flags
                (byte) 0x21, // Command: Write 1 blocks
                (byte) 0x5A, // First block (offset)
                (byte) 0x41  // Data
        };
    nfcvTag.transceive(Write);

我在 AsyncTask 中执行此操作并获得java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()异常。

有小费吗?标签是 STMicroelectronics M24LR04E-R

4

1 回答 1

1

弄清楚了。我只写了 8 位数据,而标签每个块有 32 位。添加了 3 个 0x00,写入成功。

Write = new byte[]{
            (byte) 0x02, // Flags
            (byte) 0x21, // Command: Write 1 blocks
            (byte) 0x5A, // First block (offset)
            (byte) 0x41,
            (byte) 0x00,
            (byte) 0x00,
            (byte) 0x00  
    };
nfcvTag.transceive(Write);
于 2016-04-04T22:24:04.043 回答