写入单块命令会因NfcV失败

问题描述 投票:0回答:1

我正在尝试通过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;
        }
    }
}

android tags nfc rfid iso-15693
1个回答
0
投票

将标志更改为(字节)0x22值可修复问题。

© www.soinside.com 2019 - 2024. All rights reserved.