在未使用notifyBLECharacteristicValueChange 前 writeBLECharacteristicValue可以写入成功。使用notifyBLECharacteristicValueChange后就无法 写入成功 一般都是报 {10007 property not support 当前特征值不支持此操作}。notifyBLECharacteristicValueChange中如果用writeCharaterId 就会之间报错 10005 错误
notifyCharaterId = '0000FF01-0000-1000-8000-00805F9B34FB'
{
"uuid": "0000FF01-0000-1000-8000-00805F9B34FB",
"properties": {
"read": true,
"write": true,
"notify": true,
"indicate": false
}
}
writeCharaterId = '00002B29-0000-1000-8000-00805F9B34FB';
{
"uuid": "00002B29-0000-1000-8000-00805F9B34FB",
"properties": {
"read": true,
"write": true,
"notify": false,
"indicate": false
}
},
doNotifyBLECharacteristicValueChange(){
let theBlueDevice = this.m_blueDevice;
uni.notifyBLECharacteristicValueChange({
state: true, // 启用 notify 功能
deviceId: theBlueDevice.deviceId,
serviceId: theBlueDevice.notifyServiceId,
characteristicId: theBlueDevice.notifyCharaterId,
success(res) {
console.log('启用notify特征值变化成功', res)
},fail(res) {
console.log('启用notify特征值变化失败', res)
}
})
},
doWriteBlueMachineCmd(inCmd) {
// var inCmd = "SetLabel:CHK_LABEL"; 参数值是这个
var nCmdByteSize = inCmd.length;
var theBlueDevice = that.m_blueDevice;
var theNewBuf = new ArrayBuffer(nCmdByteSize);
var dataView = new DataView(theNewBuf);
for (var i = 0; i < nCmdByteSize; ++i) {
theNewBuf2.push(inCmd.charCodeAt(i));
dataView.setUint8(i, inCmd.charCodeAt(i));
}
plus.bluetooth.writeBLECharacteristicValue({
value: theNewBuf2,
deviceId: theBlueDevice.deviceId,
serviceId: theBlueDevice.writeServiceId,
characteristicId: theBlueDevice.writeCharaterId,
success: function(res) {
setTimeout(() => {
// 接收数据 但是一直都是空的
that.doMakeReadBlueEvent();
}, 1500);
},fail: function(res) {
console.log('发送蓝牙数据 \'' + inCmd + '\' 失败 => ', res);
}
});
}
0 个回复