收藏
回答

writeBLECharacteristicValue蓝牙设备无法获取数据

API/组件名称 终端类型 微信版本 基础库版本
wx.writeBLECharacteristicValue 客户端 6.6.1 1.6.6

writeBLECharacteristicValue调用蓝牙功能此接口,与打印机连接发送数据,返回成功,但是打印机没有收到任何数据,打印机接收字符串和16进制数据,麻烦各位大神或官方技术大神帮我看看有什么问题没,代码:

var that = this

let buffer = new ArrayBuffer(1)

let dataView = new DataView(buffer)

dataView.setUint8(0, 0)

var serviceId = '';

var characteristicId = '';

wx.getBLEDeviceServices({

// 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接

deviceId: that.data.connectedDeviceId,

success: function (res) {

for (var i = 0; i < res.services.length; i++) {

if (res.services[i].isPrimary) {

serviceId = res.services[i].uuid

wx.getBLEDeviceCharacteristics({

// 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接

deviceId: that.data.connectedDeviceId,

// 这里的 serviceId 需要在上面的 getBLEDeviceServices 接口中获取

serviceId: serviceId,

success: function (res) {

for (var j = 0; j < res.characteristics.length;j++){

if (res.characteristics[j].properties.write){

characteristicId = res.characteristics[j].uuid

wx.writeBLECharacteristicValue({

deviceId: that.data.connectedDeviceId,

serviceId: serviceId,

characteristicId: characteristicId,

value: buffer,

success: function (res) {

console.log('writeBLECharacteristicValue success', res)

},

fail:function(err){

console.log('err',err)

}

})

}

}

}

})

}

}

}

})



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

1 个回答

  • Yrz.Bryant
    Yrz.Bryant
    2020-02-29

    你好,请问下这个问题解决了吗?

    2020-02-29
    有用
    回复
登录 后发表内容