BLE下ISO使用writeBLECharacteristicValue失败
发布于 7 年前 作者 pqian 10243 次浏览 来自 问答

同样的代码,在安卓手机可以正常调用writeBLECharacteristicValue向蓝牙设备写入,但是在iphone手机(版本11.2.2)上调用,返回错误编码10008,错误信息“the value’s length is invalid”,请大佬告知如何解决。代码如下:

wx.notifyBLECharacteristicValueChange({

     state: true,

     deviceId: deviceId,

     serviceId: notifyserviceId,

     characteristicId: notifycharacteristicId,

     success: function (res) {

       console.log(“notify success”)

       setTimeout(function () {

         that.writeBLECharacteristicValue(deviceId, writeserviceId, writecharacteristicId)

       }, 2000);

     },

     fail: function (res) {

       console.log(“notify fail:” + res.errMsg)

     }, complete : function() {

       wx.onBLECharacteristicValueChange(function (res) {

         console.log(res)

       });

     }

   })

 },

 writeBLECharacteristicValue: function (deviceId, writeserviceId, writecharacteristicId) {

   var that = this

   let buffer = new ArrayBuffer(1)

   let dataView = new DataView(buffer)

   dataView.setUint8(0, 0)

   wx.writeBLECharacteristicValue({

     deviceId: deviceId,

     serviceId: writeserviceId,

     characteristicId: writecharacteristicId,

     value: buffer,

     success: function (res) {

       console.log(‘write success’)

     },

     fail(res) {

       console.log(‘write fail’)

       console.log(res)

     }

   })

 },

回到顶部