I'm trying to write data to a NXP I-CODE SLI (ISO 15693 - Model#: IQC21-50P) using WRITE SINGLE BLOCK (0x21) command through the NfcV object.
Following code reads the tag successfully:
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;
}
}
}
When I try to write data to tag with the following code, data is not written to tag and I'm not getting any error either.
Here is the write single block code I use:
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;
}
}
}