// 获取要连接设备的服务
getBLEDeviceServices(deviceId) {
this.printLog("获取设备服务: " + deviceId)
wx.getBLEDeviceServices({
deviceId,
success: (res) => {
for (let i = 0; i < res.services.length; i++) {
if(res.services[i].uuid == "0000FFE0-0000-1000-8000-00805F9B34FB") {
this.getBLEDeviceCharacteristics(deviceId, res.services[i].uuid)
}
}
}
})
},
//发送前进命令
up_command() {
var that = this;
that.sendData = "bc,02,01,00,00,00,00,00,00,00,00,0a";
this.writeBLECharacteristicValue(that.sendData)
},
writeBLECharacteristicValue(sendData) {
var that = this;
let data = sendData.split(',')
let buffer = new ArrayBuffer(data.length)
let dataView = new DataView(buffer)
for (let j = 0; j < data.length; j++) {
dataView.setUint8(j, '0x' + data[j])
}
wx.writeBLECharacteristicValue({
deviceId: this._deviceId,
serviceId: this._serviceId,
characteristicId: this._characteristicId,
value: buffer,
success (res) {
// that.printLog("发送数据成功");
},
fail (res) {
that.printLog("发送数据失败")
}
})
},
本文分享自 Rice 嵌入式开发技术分享 微信公众号,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文参与 腾讯云自媒体同步曝光计划 ,欢迎热爱写作的你一起参与!