代码分享片段
https://developers.weixin.qq.com/s/CMqmTCmB7EsV
安卓上第一帧返回的是:
A5689400000001A2090330303030303030303030303030303089FF06000001006F005C0010303030303030303030303030303030004E001038363530353730343738353730303200420010343630313133303234333330323434003D0010444833313030
缺了3D0010444833313030
你好,请提供完整的代码片段
settingBlueToothListener:function(){
console.log("settingBlueToothListener");
let me=this;
wx.onBLECharacteristicValueChange(function (res) {
// var TIME = util.formatTime(new Date());
let hexStr = me.bytes2HexStr(res.value)
// console.log(hexStr);
hexStr = me.hexCharCodeToStr(hexStr);
console.log('receive frame:'+hexStr);
console.log('receive frame size:'+hexStr.length);
if(hexStr.length>8 && hexStr.indexOf('A568')==0){
let lowSitStr=hexStr.substring(4,6);
let hightSitStr=hexStr.substring(6,8);
let lenStr=hightSitStr+lowSitStr;
let frameLen=parseInt(lenStr,16);
me.currentSession['frameLen']=frameLen;
}
if(!me.currentSession['command'].hasOwnProperty('resFrame')){
me.currentSession['command']['resFrame']=hexStr;
}
else{
me.currentSession['command']['resFrame']+=hexStr;
}
//判断数据帧是否接收完毕
if(me.currentSession['frameLen']<=(me.currentSession['command']['resFrame'].length/2)){
console.log('resParsering:'+me.currentSession['command']['resFrame']);
let result=me.parsers['DYJWNA-54'].resParsering(me.currentSession['command']);
let callBack=me.currentSession['callBack']['success'];
setTimeout(function () {
callBack(result);
}, 10)
//清除当前会话
me.currentSession={};
}
})
},
console.log('wx.notifyBLECharacteristicValueChange success', data);
console.log("send frame:"+frameBuffer);
wx.writeBLECharacteristicValue({
deviceId:me.deviceUUID,
serviceId:me.serviceUUID,
characteristicId:me.WcharacteristicUUID,
value: me.hexStr2byte(frameBuffer),
success(res) {
console.log('send success',res);
},
fail(res) {
console.log('send fail',res);
},
complete(res) {
}
})
},
fail(data) {
console.log('wx.notifyBLECharacteristicValueChange fail', data);
},
complete(data) {
}
})
},