蓝牙读取数据,监听返回000000000000000000什么情况
发布于 5 年前 作者 ming12 7499 次浏览 来自 问答

write:function(){

var that=this;

var buffer = new ArrayBuffer(16)

var dataView = new DataView(buffer)

var str = ‘0xd3,0x80,0x60,0x79,0x76,0xc9,0xdd,0x46,0xe5,0x18,0xf4,0x31,0xf6,0x4e,0xb6,0x44’;

var arr = str.split(’,’)

var val;

for (var i = 0; i < arr.length; i++) {

val = parseInt(arr[i], 16)

dataView.setInt8(i, val);

}

wx.writeBLECharacteristicValue({

deviceId: that.data.deviceId,

serviceId: that.data.services,

characteristicId: that.data.characteristicsFEC7,

value: buffer,

success: function (res) {

console.log(res, ‘writeBLECharacteristicValue success’);

wx.onBLECharacteristicValueChange(function (res) {

console.log(’-writeaaaaaaaaa:’, res);

var buffer = Array.prototype.map.call(new Uint8Array(res.value), x => (‘00’ + x.toString(16)).slice(-2)).join(’’);

console.log(buffer)

})

wx.notifyBLECharacteristicValueChange({

state: true, // 启用 notify 功能

deviceId: that.data.deviceId,

serviceId: that.data.services,

characteristicId: that.data.characteristicsFEC8,

success: function (res) {

console.log(‘notifyBLECharacteristicValueChange success’, res.errMsg)

},

fail: function (res) {

console.log(‘notifyBLECharacteristicValueChange fail’, res.errMsg)

}

})

},

fail: function (res) {

console.log(res, ‘buff fail’)

}

})

},

read:function(){

var that=this;

wx.onBLECharacteristicValueChange(function (res) {

console.log(’-write:’, res);

var buffer = Array.prototype.map.call(new Uint8Array(res.value), x => (‘00’ + x.toString(16)).slice(-2)).join(’’);

console.log(buffer)

// const blueArrayBuffer = new Uint8Array(res.value);

// const base64Str = wx.arrayBufferToBase64(blueArrayBuffer);

// console.log(base64Str)

})

//读取低功耗蓝牙设备的特征值的二进制数据值

wx.readBLECharacteristicValue({

deviceId: that.data.deviceId,

serviceId: that.data.services,

characteristicId: that.data.characteristicsFEC9,

success: function (res) {

console.log(‘readBLECharacteristicValue++++++++++++++++++++++:’, res)

},

fail: function (res) {

console.log(‘readBLECharacteristicValue fail:’, res)

},

})

},

为什么写入后读取的console.log(buffer) 是000000000000000000000000000000000000  求助

回到顶部