向蓝牙设备发送“AA040500010105”的指令,代码如下:
bluetoothLock:function(){
var that = this;
that.writeBluetoothData1(‘AA040500010105’,7);
},
writeBluetoothData1: function (e, num) { //写入执行1指令
var that = this;
wx.writeBLECharacteristicValue({
deviceId: that._deviceId,
serviceId: that._serviceId,
characteristicId: that._characteristicId,
value: that.getBinaryData1(e, num),
success(res) {
console.log(‘writeBLECharacteristicValue success’, res.errMsg)
},
fail(res) {
console.log(‘writeBLECharacteristicValue fail’, res.errMsg)
}
});
},
getBinaryData1: function (message, num) { //将数据转为二进制数组
let buffer = new ArrayBuffer(num);
let dataView = new DataView(buffer);
var numTitle = 0;
for (var i = 0; i < message.length; i = i + 2) {
var numStr16 = message.substr(i, 2);
var num1 = parseInt(numStr16, 16);
dataView.setUint8(numTitle, num1);
numTitle++;
}
return buffer;
},
能够接受到返回值,可是设备就是没有响应,但同事用app下发相同指令,设备会有滴一声的响应,请问各位大佬,我是哪里写的有问题吗?
你好,麻烦提供出现问题的具体机型、微信版本号、系统版本号,以及能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)