2020-06-12
```
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)
}
})
})
}
}
}
```