【问题标题】:Writing Single Block command fails over NfcV写入单块命令故障转移 NfcV
【发布时间】:2019-04-25 19:48:28
【问题描述】:

我正在尝试通过 NfcV 对象使用 WRITE SINGLE BLOCK (0x21) 命令将数据写入 NXP I-CODE SLI(ISO 15693 - 型号:IQC21-50P)。

以下代码读取标签成功:

Tag currentTag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
byte[] id = currentTag.getId();
for (String tech : currentTag.getTechList()) {
    if (tech.equals(NfcV.class.getName())) {
        NfcV nfcvTag = NfcV.get(currentTag);
        try {
            nfcvTag.connect();
            // nfcvTag.getMaxTransceiveLength() returns 253
            int offset = 0;  // offset of first block to read
            int blocks = 8;  // number of blocks to read
            byte[] cmd = new byte[] {
                    (byte) 0x60,  // flags: addressed (= UID field present)
                    (byte) 0x23, // command: READ MULTIPLE BLOCKS
                    (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,  // placeholder for tag UID
                    (byte) (offset & 0x0ff),  // first block number
                    (byte) ((blocks - 1) & 0x0ff)  // number of blocks (-1 as 0x00 means one block)
            };
            System.arraycopy(id, 0, cmd, 2, 8);
            byte[] response = nfcvTag.transceive(cmd);
        } 
        catch (IOException e) {
            Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
            return;
        }
    }
}

当我尝试使用以下代码将数据写入标签时,数据未写入标签,我也没有收到任何错误。

这是我使用的写单块代码:

Tag currentTag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
byte[] id = currentTag.getId();
String dataString = "CGH13F1V0AK1234567:6 012 ";

for (String tech : currentTag.getTechList()) {
    if (tech.equals(NfcV.class.getName())) {
        NfcV nfcvTag = NfcV.get(currentTag);
        try {
            nfcvTag.connect();
            int offset = 0;  // offset of first block to read
            int blocks = 8;  // number of blocks to read
            byte[] data = convertHexToByte(convertStringToHex(dataString));
            byte[] cmd = new byte[] {
                    (byte)0x60, // FLAGS
                    (byte)0x21, // WRITE SINGLE COMMAND
                    (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, // UID
                    (byte)0x00, // OFFSET
                    (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00  //DATA
            };
            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);
            }

        } 
        catch (IOException e) {
            Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
            return;
        }
    }
}

【问题讨论】:

  • 您是否尝试在未设置选项标志的情况下发送写入命令? IE。 FLAGS 设置为 0x40?
  • 感谢迈克尔让我走上了正确的道路。我将选项标志更改为 0x22,一切正常。
  • @Kamila 我正在尝试使用您的代码读取 nfcv 标签,但我收到“标签丢失”错误。你能帮我解决这个问题吗?

标签: android tags nfc rfid iso-15693


【解决方案1】:

将标志更改为 (byte)0x22 值修复了问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-09
    • 1970-01-01
    • 2015-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多