跳至主要內容

BluetoothRemoteGATTCharacteristic.readValue()

BFChainInterfaceBluetoothRemoteGATTCharacteristicreadValue小于 1 分钟

读取特征值的方法

BluetoothRemoteGATTCharacteristic.readValue()

参数

返回值

返回一个Promise, resolve对象一个DataView对象

示例

  import { bluetoothPlugin } from "@plaoc/plugins";

  bluetoothPlugin
  .open()
  .then(res => {
    if(res.success){
      const options = {
        acceptAllDevices: true,
        optionalServices: ["00003802-0000-1000-8000-00805f9b34fb"],
      }
      return bluetoothPlugin.requestAndConnectDevice(options)
    }
  })
  .then(res => {
    if(res.success){
      const bluetoothRemoteGATTServer = res.data;
      return bluetoothRemoteGATTServer
      .getPrimaryService("00003802-0000-1000-8000-00805f9b34fb")
    }
  })
  .then(res => {
    if(res.success){
      const bluetoothRemoteGATTService = res.data;
      bluetoothRemoteGATTService.getCharacteristic("00004a02-0000-1000-8000-00805f9b34fb")
    }
  })
  .then(res => {
    if(res.success){
      const bluetoothRemoteGATTCharacteristic = res.data;
      return bluetoothRemoteGATTCharacteristic.readValue()
    }
  })
  .then(res => {
    if(res.success){
      // value === res.data
    }
  })
  .catch(err => console.error(err))

平台兼容性

属性/方法/事件AndroidIOSDesktop-DevDesktop
readValueX

相关链接

BluetoothRemoteGATTCharacteristic

评论
  • 按正序
  • 按倒序
  • 按热度
Powered by Waline v2.15.7