2020-06-12

2020-06-12  本文已影响0人  cmsok

```

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)

          }

        })

      })

    }

  }

}

```

上一篇下一篇

猜你喜欢

热点阅读