首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用于NfcV的写锁块命令

用于NfcV的写锁块命令
EN

Stack Overflow用户
提问于 2020-11-27 19:11:57
回答 1查看 119关注 0票数 0

我正在尝试将数据锁定到恩智浦ICODE SLIX SL2S2002标签类型5 (ISO 15693),通过基于离子的应用程序中的NfcV对象使用WRITE SINGLE BLOCKS命令将其设置为只读:

代码语言:javascript
复制
    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 I”和READ_SINGLE_BLOCK命令的答案。离子方法makeReadOnly()不起作用,因为它被标签阻止。我必须通过字节来设置它。我不知道我是否必须使用Int8Array或Unit8Array,我是否必须在tagId上使用reverse(),因为十六进制是镜像的,或者我只是传递UID字节串而不是十六进制字符串?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-01-26 18:55:24

代码语言:javascript
复制
     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));
        });

解决了这个问题!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65036372

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档