NfcV 的写入锁定块命令
Write Lock Block command for NfcV
我正在尝试将数据锁定到 NXP ICODE SLIX SL2S2002 标签类型 5 (ISO 15693),以通过基于离子的应用程序中的 NfcV 对象使用 WRITE SINGLE BLOCKS 命令使其成为只读:
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');
});
我不知道我必须为每个块传递哪些字节。我使用 ionic 的 phoneGap-NFC 插件。每次我尝试将其设置为只读时,我都会得到 '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));
});
已解决问题![=11=]
我正在尝试将数据锁定到 NXP ICODE SLIX SL2S2002 标签类型 5 (ISO 15693),以通过基于离子的应用程序中的 NfcV 对象使用 WRITE SINGLE BLOCKS 命令使其成为只读:
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');
});
我不知道我必须为每个块传递哪些字节。我使用 ionic 的 phoneGap-NFC 插件。每次我尝试将其设置为只读时,我都会得到 '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));
});
已解决问题![=11=]