wx.BLEcharacterticValue+read 多次调用的问题?
发布于 7 年前 作者 xiulan14 4276 次浏览 来自 官方Issues

目的:我要获取’0000FFF0-0000-1000-8000-00805F9B34FB’下FFF2和FFF6的特征值并赋值。


直接上代码:


  // (function(){
    //获取特征值
    wx.getBLEDeviceCharacteristics({
      deviceId,
      serviceId: '0000FFF0-0000-1000-8000-00805F9B34FB',
      success: function (res1) {
        console.log('chara_res:', res1)
 
        var charaArr = res1.characteristics[2]

 
        wx.onBLECharacteristicValueChange(function (res1) {
          var temp1 = ab2hex(res1.value)
          console.info('pfmc1:', temp1)
          var power = (temp1[0] * 16 + temp1[1] * 1)
 
          //设置渲染层参数power
          _this.setData({
            power,
          })
          console.info("hextodec:", power)
        })
 
        wx.readBLECharacteristicValue({
          deviceId,
          serviceId,
          characteristicId: charaArr.uuid,
          success: function (res1) {
            console.log('readBLECharacteristicValue:', res1.errCode)
          },
        })
      },
    })
  // })();
 
  // (function(){
    //获取特征值
    wx.getBLEDeviceCharacteristics({
      deviceId,
      serviceId: '0000FFF0-0000-1000-8000-00805F9B34FB',
      success: function (res2) {
        console.log('chara_res:', res2)
 
        var charaArr = res2.characteristics[6]
        // console.info('charaarr:', charaArr)
 
        wx.onBLECharacteristicValueChange(function (res2) {
          var temp2 = ab2hex(res2.value)
          console.info('pfmc2:', temp2)
 
          var interval = (temp2[0] * 16 + temp2[1] * 1)
          //设置渲染层参数interval
          _this.setData({
            interval,
          })
 
          console.info("hextodec:", interval)
        })
 
        wx.readBLECharacteristicValue({
          deviceId,
          serviceId,
          characteristicId: charaArr.uuid,
          success: function (res2) {
            console.log('readBLECharacteristicValue:', res2.errCode)
          },
        })
      },
    })
  // })();
 

1、日志打印输出了两次pfmc2:???---------------------------------------------------------------

    理论上应该输出pfmc1:第一次数据;pfmc2:第二次数据。

    应该怎么修改可以分别获取FFF2,FFF6的特征值数据并赋值?

1 回复

怎一个惨字了得

回到顶部