/ 执行演示分包操作 /
writeDevice(_Buffer) {
let _self = this;
let Num = 0;
let ByteLength = _Buffer.byteLength;
console.log(ByteLength, 'ByteLength')
let i = 1;
while (ByteLength > 0) {
i++;
let TmpBuffer;
console.log(i)
console.log("TmpBuffer", TmpBuffer)
console.log("Num", Num)
console.log("ByteLength", ByteLength)
console.log(_self.DeviceID, _self.serviceId, _self.characterId)
if (ByteLength > 20) {
TmpBuffer = _Buffer.slice(Num, Num + 20);
Num += 20;
ByteLength -= 20;
let _self = this;
uTool.delayed(200).then(() => {
console.log('执行常规循环')
// setTimeout(() => {
uni.writeBLECharacteristicValue({
deviceId: _self.DeviceID,
serviceId: _self.serviceId,
characteristicId: _self.characterId,
value: TmpBuffer,
success: (res) => {
/ 发送成功 /
console.log('写入数据成功', res)
},
fail: (error) => {
/* 发送失败 */
console.log('写入数据失败', error)
}
})
// }, 500)
})
} else {
TmpBuffer = _Buffer.slice(Num, Num + ByteLength)
Num += ByteLength
ByteLength -= ByteLength
/* 当长度不满20的时候执行最后一次发送即可 */
uTool.delayed(1000).then(() => {
console.log('执行最后一次')
// _self.sendAlwaydata()
// setTimeout(() => {
uni.writeBLECharacteristicValue({
deviceId: _self.DeviceID,
serviceId: _self.serviceId,
characteristicId: _self.characterId,
value: TmpBuffer,
success: (res) => {
/* 发送成功 */
console.log('最后一次写入成功', res)
},
fail: (error) => {
/* 发送失败 */
console.log('最后一次写入失败', error)
// _self.sendAlwaydata()
}
})
// }, 400)
})
}
}
},
木杉丶
最后有解决方案吗
2021-09-17 18:27