美文网首页
2020-06-12

2020-06-12

作者: cmsok | 来源:发表于2020-06-12 10:13 被阅读0次

    ```

    functionwriteTest(msg){

    letbuffer = hexStringToArrayBuffer(msg);

    letpos = 0;

    letbytes = buffer.byteLength;

    console.log("bytes", bytes)

    while(bytes > 0) {

    lettmpBuffer;

    if(bytes > 20) {

    returndelay(0.25).then(() => {

            tmpBuffer = buffer.slice(pos, pos + 20);

            pos += 20;

            bytes -= 20;

    console.log("tmpBuffer", tmpBuffer)

            wx.writeBLECharacteristicValue({

              deviceId: deviceId,

              serviceId: serviceId,

              characteristicId: writeId,

              value: tmpBuffer,

              success(res) {

    console.log('第一次发送', res)

              }

            })

          })

    }else{

    returndelay(0.25).then(() => {

            tmpBuffer = buffer.slice(pos, pos + bytes);

            pos += bytes;

            bytes -= bytes;

            wx.writeBLECharacteristicValue({

              deviceId: deviceId,

              serviceId: serviceId,

              characteristicId: writeId,

              value: tmpBuffer,

              success(res) {

    console.log('第二次发送', res)

              },

    fail:function(res) {

    console.log('发送失败', res)

              }

            })

          })

        }

      }

    }

    ```

    相关文章

      网友评论

          本文标题:2020-06-12

          本文链接:https://www.haomeiwen.com/subject/zgqgtktx.html