收藏
回答

wx.onBluetoothDeviceFound()函数无法获取正确的ArrayBuffer?

windows操作系统,版本号:版本(1.06.2504010win32-x64)。

代码片段:

onBluetoothDeviceFound() {

    wx.onBluetoothDeviceFound((res) => {

      res.devices.forEach(device => {

        const foundDevices = this.data.devices

        const idx = inArray(foundDevices, 'deviceId', device.deviceId)

        const data = {}

        if (idx === -1{

          data[`devices[${foundDevices.length}]`= device//设备不存在于列表中, 把设备添加到数组末尾

        } else {

          data[`devices[${idx}]`= device//设备已经存在,更新已有设备信息

        }

        this.setData(data)//使用 setData 更新页面数据,触发视图刷新。

      })

    })

  },

// ArrayBuffer转16进度字符串示例

function ab2hex(buffer) {

  if (!buffer || buffer.length <= 0{

    return "";

  }

  var hexArr = Array.prototype.map.call(

    new Uint8Array(buffer),

    function (bit) {

      return ('00' + bit.toString(16)).slice(-2)

    }

  )

  return hexArr.join('').toUpperCase();

}



问题:在微信端获取的“ArrayBuffer”数据,在使用ab2hex()函数后,与安卓app的lightblue软件所获取的值不一样或者直接就没有,但是其它的参数可以正常获取到。请问我该如何解决,谢谢。


回答关注问题邀请回答
收藏

2 个回答

  • 倔强的海绵
    倔强的海绵
    08-05

    我开发环境是windows系统,测试用的是荣耀手机

    08-05
    有用
    回复
  • 智能回答 智能回答 本次回答由AI生成
    07-30
    有用
登录 后发表内容