wx.writeBLECharacteristicValue,向低功耗蓝牙设备特征值中写入二进制数据 - 加速度jsudo

wx.writeBLECharacteristicValue,向低功耗蓝牙设备特征值中写入二进制数据

2013-12-19
0 Views
0 Comments
闻道君

基础库 1.1.0 开始支持,低版本需做兼容处理

向低功耗蓝牙设备特征值中写入二进制数据。注意:必须设备的特征值支持write才可以成功调用,具体参照 characteristic 的 properties 属性

tips: 并行调用多次读写接口存在读写失败的可能性

OBJECT参数说明:

参数 类型 必填 说明
deviceId String 是 蓝牙设备 id,参考 device 对象
serviceId String 是 蓝牙特征值对应服务的 uuid
characteristicId String 是 蓝牙特征值的 uuid
value ArrayBuffer 是 蓝牙设备特征值对应的二进制值
success Function 是 成功则返回本机蓝牙适配器状态
fail Function 否 接口调用失败的回调函数
complete Function 否 接口调用结束的回调函数(调用成功、失败都会执行)

success返回参数:

参数 类型 说明
errMsg String 成功:ok,错误:详细信息

示例代码:

// 向蓝牙设备发送一个0x00的16进制数据
let buffer = new ArrayBuffer(1)
let dataView = new DataView(buffer)
dataView.setUint8(0, 0)

wx.writeBLECharacteristicValue({
  // 这里的 deviceId 需要在上面的 getBluetoothDevices 或 onBluetoothDeviceFound 接口中获取
  deviceId: deviceId,
  // 这里的 serviceId 需要在上面的 getBLEDeviceServices 接口中获取
  serviceId: serviceId,
  // 这里的 characteristicId 需要在上面的 getBLEDeviceCharacteristics 接口中获取
  characteristicId: characteristicId,
  // 这里的value是ArrayBuffer类型
  value: buffer,
  success: function (res) {
    console.log('writeBLECharacteristicValue success', res.errMsg)
  }
})

****更多行业产品开发方案,请关注 JSudo****

<以上资讯仅供参考,如需解决具体问题,建议您关注作者;如果有软件产品开发需求,可在线咨询获取产品开发方案和报价>

软件 软件开发 软件定制 软件公司
微信客服二维码

加客服微信获取更多内容