sendData(str) { let that = this; let dataBuffer = new ArrayBuffer(str.length) let dataView = new DataView(dataBuffer) for (var i = 0; i < str.length; i++) { dataView.setUint8(i, str.charAt(i).charCodeAt()) } let dataHex = that.ab2hex(dataBuffer); this.writeDatas = that.hexCharCodeToStr(dataHex); wx.writeBLECharacteristicValue({ deviceId: that.connectedDeviceId, serviceId: that.services[0].uuid, characteristicId: that.notifyCharacteristicsId, value: dataBuffer, success: function (res) { console.log('发送的数据:' + that.writeDatas) console.log('message发送成功')
}, fail: function (res) { console.log('message发送失败') } }) } })
看看代码
let that = this;
let dataBuffer = new ArrayBuffer(str.length)
let dataView = new DataView(dataBuffer)
for (var i = 0; i < str.length; i++) {
dataView.setUint8(i, str.charAt(i).charCodeAt())
}
let dataHex = that.ab2hex(dataBuffer);
this.writeDatas = that.hexCharCodeToStr(dataHex);
wx.writeBLECharacteristicValue({
deviceId: that.connectedDeviceId,
serviceId: that.services[0].uuid,
characteristicId: that.notifyCharacteristicsId,
value: dataBuffer,
success: function (res) {
console.log('发送的数据:' + that.writeDatas)
console.log('message发送成功')
},
fail: function (res) {
console.log('message发送失败')
}
})
}
})