Options
All
  • Public
  • Public/Protected
  • All
Menu

蓝牙协议 统称 BLE,特指 4.0 以上的协议,3.0 或者 2.0 不支持

蓝牙协议包含了两种协议:

这两种协议有什么区别?

UCodeBle 是 uCode 自己依赖 uCodeLink 实现的蓝牙协议,它可以直接在程序中获取到蓝牙列表,进一步的可以获取一些额外的权限,但是缺陷就是必须依赖 uCodeLink ,而且 平台有所限制,PC 只支持 WindowsMacOS,移动端的只有 APP 版本的才支持

WebBle 则是走的浏览器的默认的 WebBluetooth 协议,但目前沙盒系统的问题,暂不支持开放,后续解决了权限问题,会重新开放

这两种协议都是继承自 UCodeBleProtocol

另外由于两种协议的扫描方式不一样:

UCodeBle 的设备类型是 扫描连接设备类型 也就是 DiscoverDeviceType

Webble 的设备类型是 自动连接设备类型 也就是 AutoConnectDeviceType

要注意的是,注册器也是分成了两个:

Index

Type aliases

BleChangeDataValue

BleChangeDataValue: { buffer: ArrayBuffer; byteLength: number; byteOffest: number }

蓝牙 onChange 的数据

Type declaration

  • buffer: ArrayBuffer
  • byteLength: number
  • byteOffest: number

BleCharacteristic

BleCharacteristic: { name?: string; readable?: boolean; uuid: BluetoothCharacteristicUUID } | BluetoothCharacteristicUUID

BleCharacteristicsMap

BleCharacteristicsMap: Map<BluetoothCharacteristicUUID, BluetoothRemoteGATTCharacteristic>

BleFilterType

BleFilterType: BluetoothLEScanFilter[]

蓝牙过滤类型,和标准的 Webbluetooth 一致:BluetoothLEScanFilter

BleRegisterOptions

BleRegisterOptions: { defaultWriteCharacteristicUUID?: BluetoothCharacteristicUUID; filters?: BleFilterType; optionalServices?: BluetoothServiceUUID[]; queueOptions?: QueueConstructorType; scanTime?: number; services: BleServiceUUID | BleServiceUUID[]; customDeviceName?: any }

蓝牙注册 Options

Type declaration

  • Optional defaultWriteCharacteristicUUID?: BluetoothCharacteristicUUID

    需要提供了 defaultWriteCharacteristicUUID, {@link CommonBleHardwareDevice.send} 才会生效

  • Optional filters?: BleFilterType
  • Optional optionalServices?: BluetoothServiceUUID[]

    requestDevices 的一个参数,uCodeBle 也适用 参考

  • Optional queueOptions?: QueueConstructorType

    队列参数

  • Optional scanTime?: number

    扫描时间

  • services: BleServiceUUID | BleServiceUUID[]
  • customDeviceName?:function
    • customDeviceName(deviceName: string): string
    • 自定义蓝牙设备名:可以通过一些数据,自己生成新的设备名

      Parameters

      • deviceName: string

      Returns string

BleServiceUUID

BleServiceUUID: { characteristics: BleCharacteristic[]; serviceUUID: BluetoothServiceUUID }

蓝牙 Service 以及它下面的 characteristics

Type declaration

CommonBleDataType

CommonBleDataType: { data: Buffer; uuid: BluetoothCharacteristicUUID }

Type declaration

  • data: Buffer
  • uuid: BluetoothCharacteristicUUID

Variables

UCodeBleDeviceType

UCodeBleDeviceType: DiscoverDeviceType = ...

UCodeBle 设备类型

const devicetype = {
id: DeviceTypeID.ucodeble,
name: '蓝牙协议'
conenctType: 'discover'
};

WebBleDeviceType

WebBleDeviceType: AutoConnectDeviceType = ...

Webble 设备类型

const devicetype = {
id: DeviceTypeID.webble,
name: '蓝牙协议'
conenctType: 'auto'
};

Functions

getUCodeBleDeviceRegister

getWebBleDeviceRegister

Generated using TypeDoc