我有一些ISO15693 / Tag-it HF-I Plus芯片,需要在它们上面写点东西。这些芯片非常简洁,我现在阅读了大量的pdf告诉我所有相同的内容。但没有任何作用,我总是得到Transceive Failed错误。
我在收发命令中发送这些数据:
Byte: <data>
0: 0x00 // pdf says the tag understands only flag = 0x00
1: 0x21 // write single block
2-10: ID // needs to be send for this tag, only supports addressed mode
11: 0x00 // Block ID, try to write to block 0
12-16: DATA // LSB First
17-18: CRC16 // do i need to send this? and if yes, LSB first?
我尝试了非常不同的标志和写入模式,但它们都不起作用:
Flags: 0x01, 0x02, 0x20,0x22,0x42,0x40,0x80,0x82
Modes: 0x21,0xA2 (+ Vendor Mode 0x07)
这是我的写功能:
private void write(Tag tag) throws IOException, FormatException {
if (tag == null) {
return;
}
NfcV nfc = NfcV.get(tag);
byte[] ID = tag.getId();
nfc.connect();
Log.d(TAG, "Data: " + new String(((EmergencyApplication) getApplication()).getData()));
byte[] data = ((EmergencyApplication) getApplication()).getData();
// NfcV Tag has 64 Blocks with 4 Byte
if ((data.length / 4) > 64) {
// ERROR HERE!
Log.d(TAG, "too much data...");
}
for (int i = 0; i < data.length; i++) {
byte[] arrByte = new byte[17];
// Flags
arrByte[0] = 0x00; // Tag only supports flags = 0
// Command
arrByte[1] = 0x21;
// ID
Log.d(TAG, "Found ID length: " + ID.length + "... ID: " + Arrays.toString(ID));
System.arraycopy(ID, 0, arrByte, 2, 8);
// block number
arrByte[10] = (byte) (i);
// data
// TODO send LSB first...
System.arraycopy(data, i * 4, arrByte, 11, 4);
// CRC 16 of all command
byte[] check = new byte[15];
System.arraycopy(arrByte, 0, check, 0, 15);
int crc = CRC.crc16(check);
arrByte[15] = (byte) (crc >> 8);
arrByte[16] = (byte) (crc & 0xFF);
Log.d(TAG, "Writing Data: " + Arrays.toString(arrByte));
byte[] result = nfc.transceive(arrByte);
Log.d(TAG, "got result: " + Arrays.toString(result));
}
nfc.close();
Toast.makeText(this, "wrote to tag", Toast.LENGTH_LONG).show();
}
这是Nexus S的另一个错误吗?我使用Cyanogenmod 10.1.2,所以我认为Tag Lost Bug在这里得到了修复......我显然可以阅读标签,如果我使用NFC标签信息应用程序,它会向我显示所有块清晰可写。 我已阅读这些PDF文件:
http://rfidshop.com.hk/datasheet%20tag/philip%20icode%20SLI.pdf - 我标签的数据表 http://www.waazaa.org/download/fcd-15693-3.pdf - ISO15693-3数据表 http://www.ti.com/lit/ug/scbu003a/scbu003a.pdf - Tag-it HF-I Plus数据表
我用这里的代码测试了阅读:Reading a NXP ICODE SLI-L tag with Android - 它适用于所有64个块,但是写入仍然无效......即使是flag = 0x20 ......
编辑:我现在看到卡上的DSFID是0x00
,这意味着ISO15693-3卡根本不可写:
如果VICC不支持其节目,VICC应该 回复零值(&#39; 00&#39;)
这是发送0x2B
时的字节[]:
DSFID \ / AFI
| |
v v
infoRmation: [0, 15, 120, 40, -51, -51, 119, -128, 7, -32, 0, 0, 63, 3, -117]
答案 0 :(得分:4)
找到一些东西,我想分享:
但最糟糕的是,标签在编译到标签编写器的时间内没有响应。您将获得Tag is lost.
例外,但数据将被写入标签!因此,解决方案是忽略此异常并在写入后验证数据,如果不起作用则再次尝试。
我目前的编写代码如下:
public static void write(Tag tag, byte[] data) throws IOException, FormatException,
InterruptedException {
if (tag == null) {
return;
}
NfcV nfc = NfcV.get(tag);
nfc.connect();
Log.d(TAG, "Max Transceive Bytes: " + nfc.getMaxTransceiveLength());
// NfcV Tag has 64 Blocks with 4 Byte
if ((data.length / 4) > 64) {
// ERROR HERE!
Log.d(TAG, "too much data...");
}
if ((data.length % 4) != 0) {
byte[] ndata = new byte[(data.length) + (4 - (data.length % 4))];
Arrays.fill(ndata, (byte) 0x00);
System.arraycopy(data, 0, ndata, 0, data.length);
data = ndata;
}
byte[] arrByte = new byte[7];
// Flags
arrByte[0] = 0x42;
// Command
arrByte[1] = 0x21;
for (int i = 0; i < (data.length / 4); i++) {
// block number
arrByte[2] = (byte) (i);
// data, DONT SEND LSB FIRST!
arrByte[3] = data[(i * 4)];
arrByte[4] = data[(i * 4) + 1];
arrByte[5] = data[(i * 4) + 2];
arrByte[6] = data[(i * 4) + 3];
Log.d(TAG, "Writing Data to block " + i + " [" + printHexString(arrByte) + "]");
try {
nfc.transceive(arrByte);
} catch (IOException e) {
if (e.getMessage().equals("Tag was lost.")) {
// continue, because of Tag bug
} else {
throw e;
}
}
}
nfc.close();
}
它运作良好。
如果存在真正的错误,例如消息未被理解,您将收到Transceive Failed
消息。