NfcV的写入锁定块命令



我正试图通过基于离子的应用程序中的NfcV对象使用WRITE SINGLE BLOCKS命令将数据锁定到NXP ICODE SLIX SL2S2002标记类型5(ISO 15693(,使其只读:

private readonly cmdISO15693 = {
READ_SINGLE_BLOCK: 0x20,
WRITE_SINGLE_BLOCK: 0x21,
LOCK_BLOCK: 0x22
};
this.nfc.connect('android.nfc.tech.NfcV', 500)
.then(
(data) => {
console.log('connected to', this.nfc.bytesToHexString(tag.id.reverse()).toUpperCase());
console.log('maxTransceiveLength: ', data);
const offset = 0; // offset of first block to read
const blocks = 8; // number of blocks to read
const bytesOfText: number[] = this.nfc.stringToBytes(text);
console.log('bytesOfText: ', bytesOfText);
console.log('hex string: ', this.nfc.bytesToHexString(bytesOfText));
let cmd = new Int8Array([
0x60, // 0: flags: addressed (= UID field present) or 0x90 0x60 0x40 0x20??
this.cmdISO15693.READ_SINGLE_BLOCK, // 1: command
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  // 2-9 placeholder for tag UID
0x00  // 10: block number
// 0x00, 0x00, 0x00, 0x00  // 11- DATA
// ((blocks - 1) & 0x0ff)  // number of blocks (-1 as 0x00 means one block)
]);
console.log('cmd: ', [...cmd]);
// tag uid in which direction
cmd = arrayCopy(tag.id.reverse(), 0, cmd, 2, 8);
console.log('cmd new: ', [...cmd]);
console.log('cmd buffer: ', cmd.buffer);
// arrayCopy(bytesOfText, 0, cmd, 11, 4);
this.nfc.transceive(cmd.buffer)
.then((res: ArrayBuffer) => {
console.log('transceive result:', res);
try {
console.log(Utf8ArrayToStr(res));
} catch (e) {
console.log('Utf8ArrayToStr not possible', e);
}
this.nfc.close().then(() => console.log('closed connection'))
.catch((err) => console.log('error closing', err));
})
.catch((err) => {
console.log('error while transceive', err);
this.displayToast('Error to write the RFID-Chips.', 'warning');
});

我不知道每个块需要传递哪些字节。我使用phoneGap NFC插件用于ionic。每次我试图将其设置为只读时,我都会得到"Tag was lost"(标记丢失(的答案,READ_SINGLE_BLOCK命令也是如此。Ionic方法makeReadOnly((不起作用,因为它被标记阻止了。我必须用字节来设置它。我不知道我必须使用Int8Array还是Unit8Array,是因为十六进制被镜像而必须对tagId使用reverse((,还是我只传递UID字节串而不是十六进制?

this.nfc.connect('android.nfc.tech.NfcV', 500)
.then(
async () => {
const blocks = 28; // 28 read by app TagInfo memory size: 28 blocks with 4 bytes per block
const cmdLock = this.cmdISO15693.OPTION_FLAG  // 0 flag addressed
+ ' ' + this.cmdISO15693.LOCK_BLOCK        // 1 command
+ ' ' + this.tagIdHexArr.join(' ');         // 2-9 tag uid
let blockError = false;
let resTransceive: ArrayBuffer;
for (let i = 0; i < blocks; i++) {
const block = this.nfc.bytesToHexString([i]).toUpperCase();
const cmd = cmdLock + ' ' + block;
try {
resTransceive = await this.nfc.transceive(cmd);
try {
const view = new Uint8Array(resTransceive);
const resHex = this.nfc.bytesToHexString([...view]);
console.log(resHex);
} catch (e) {
console.log(e);
}
} catch (e) {
blockError = true;
return;
}
if (blockError) {
return;
}
}
if (blockError) {
this.notification.push(new Notification(NotificationType.ERROR, 'Fehler beim Setzen des Schreibschutzes.'));
}
this.nfc.close().then(() => console.log('Closed connection'))
.catch((err) => console.log('Error closing: ', err));
});

修复了问题!

相关内容

  • 没有找到相关文章

最新更新