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)

}

})

}

}

}

})

}

}

}

})



展开全部
收起
0回答
提交回答
  • 至过去的我

    2044人对此回答表示赞同

    我是未来的你,你现在是不是在年找寻小程序答案。你不要感觉诧异,给你来信原因,就是让你不在后悔。今天去学习如何推广小程序,相信......点击查看更多>
    发布于
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
咨询热线

13312967497

扫码添加业务即可随时咨询 还可领取小程序推广攻略

业务咨询: 13312967497
扫码咨询

扫码咨询套餐

回到顶部