千羽羊驼
千羽羊驼
  • 发布:2020-06-08 16:59
  • 更新:2020-06-17 09:27
  • 阅读:624

蓝牙下发二进制串偶尔失败

分类:uni-app

如题,同一串二进制串,成功下发的几率约为80%,偶尔失败,有遇到同样问题的吗?为什么?```javascript
var that = this;
var bleKey = iotKey;
bleKey = Array.prototype.map.call(new Uint8Array(uni.base64ToArrayBuffer(bleKey)), x => ('00' + x.toString(16)).slice(
-2)).join("");
var typedArray = new Uint8Array(bleKey.match(/[\da-f]{2}/gi).map(function(h) {
return parseInt(h, 16)
}))
for (var i = 0; i < typedArray.length; i += 20) {
var endLength = 0
if (i + 20 < typedArray.length) {
var senddata = typedArray
let buffer = new ArrayBuffer(20)
let dataView = new DataView(buffer)
let dataSend = []
for (var j = i; j < i + 20; j++) {
dataView.setUint8(j - i, senddata[j])
dataSend.push(dataView.getUint8(j - i))
}
uni.writeBLECharacteristicValue({
deviceId: that.deviceId,
serviceId: that.serviceId,
characteristicId: that.uartRXCharacteristic.uuid,
value: buffer,
success: function(res) {
console.log('多包', res.errMsg)
},
fail: function(res) {
console.log(buffer)
console.log('发送失败', res.errMsg)
}
})
} else {
var senddata = typedArray
if (20 < typedArray.length) {
endLength = senddata.length - i
} else {
endLength = senddata.length
}
let buffer = new ArrayBuffer(endLength)
let dataView = new DataView(buffer)
let dataSend = []
for (var j = i; j < senddata.length; j++) {
dataView.setUint8(j - i, senddata[j])
dataSend.push(dataView.getUint8(j - i))
}
uni.writeBLECharacteristicValue({
deviceId: that.deviceId,
serviceId: that.serviceId,
characteristicId: that.uartRXCharacteristic.uuid,
value: buffer,
success: function(res) {},
fail: function(res) {
console.log('发送失败', res.errMsg)
}
})
}
}

2020-06-08 16:59 负责人:无 分享
已邀请:
千羽羊驼

千羽羊驼 (作者)

这社区死气沉沉的

y***@163.com

y***@163.com

坑多没人填,uniapp 是个好东西,真希望官方把多完善完善。

该问题目前已经被锁定, 无法添加新回复