writeBLECharacteristicValue蓝牙设备无法获取数据
发布于 5 年前 作者 yangzheng 11720 次浏览 来自 问答

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)

}

})

}

}

}

})

}

}

}

})

回到顶部