You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
871 B
JavaScript
27 lines
871 B
JavaScript
5 months ago
|
// 发送指令工具类
|
||
|
const serviceId = "0000FFF0-0000-1000-8000-00805F9B34FB"; //写服务ID
|
||
|
const writeCharacteristicId = "0000FFF6-0000-1000-8000-00805F9B34FB"; //写特征ID
|
||
|
const SendCommandUtil = {
|
||
|
sendPackage(deviceId, packageData){
|
||
|
// 通过蓝牙向设备写入命令
|
||
|
wx.writeBLECharacteristicValue({
|
||
|
deviceId: deviceId, // 蓝牙设备 ID
|
||
|
serviceId: serviceId, // 蓝牙服务 UUID
|
||
|
characteristicId: writeCharacteristicId, // 蓝牙特征 UUID
|
||
|
value: packageData.buffer, // 发送的命令缓冲区
|
||
|
success: (res) => {
|
||
|
// console.log('命令发送成功', res);
|
||
|
},
|
||
|
fail: (err) => {
|
||
|
console.error('命令发送失败', err);
|
||
|
},
|
||
|
complete: (res) => {
|
||
|
// console.log('接口调用结束', res);
|
||
|
},
|
||
|
});
|
||
|
},
|
||
|
|
||
|
};
|
||
|
|
||
|
// 导出模块
|
||
|
module.exports = SendCommandUtil;
|