【问题标题】:Write Lock Block command for NfcV为 NfcV 写入锁定块命令
【发布时间】:2020-11-27 11:11:56
【问题描述】:

我正在尝试将数据锁定到 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');
              });

我不知道我必须为每个块传递哪些字节。我将 phoneGap-NFC 插件用于离子。每次我尝试将其设置为只读时,我都会得到“标签丢失”的答案,并且也会通过 READ_SINGLE_BLOCK 命令得到答案。 Ionic 方法 makeReadOnly() 不起作用,因为它被标签阻止了。我必须通过字节来设置它。 我不知道我必须使用 Int8Array 还是 Unit8Array,我是否必须在 tagId 上使用 reverse(),因为 hex 是镜像的,还是我只是传递 UID 字节串而不是 hexstring?

【问题讨论】:

    标签: android typescript nfc rfid iso-15693


    【解决方案1】:
         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));
            });
    

    解决了问题!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-09
      • 1970-01-01
      • 2013-11-16
      • 2021-11-10
      • 2021-12-28
      • 2020-04-11
      • 1970-01-01
      • 2021-01-30
      相关资源
      最近更新 更多