警告
本文档已存档,组件在当前版本的 Windows 社区工具包中不可用。
虽然目前没有将此组件移植到 8.x 的计划,但欢迎社区表达兴趣或参与将其包含。
更多信息,请参阅:
原始文档如下。
BluetoothLEHelper 类提供用于轻松枚举、连接到蓝牙 LE 外围设备并与之交互的功能。
BluetoothLEHelper 类
属性
| 资产 |
类型 |
Description |
| BluetoothLeDevices |
ObservableCollection<ObservableBluetoothLEDevice> |
获取可用蓝牙设备的列表 |
| IsEnumerating |
布尔 |
获取一个值,该值指示应用当前是否正在枚举 |
| IsPeripheralRoleSupported |
布尔 |
获取一个值,该值指示此设备是否支持外围模式 |
| 中央角色是否支持 |
布尔 |
获取一个值,该值指示此设备是否支持中央角色 |
Methods
| Methods |
返回类型 |
Description |
| StartEnumeration() |
void |
启动蓝牙 le 设备的枚举 |
| StopEnumeration() |
void |
停止蓝牙设备的枚举 |
事件
| 事件 |
Description |
| 枚举完成 |
枚举完成时的一个事件 |
ObservableBluetoothLEDevice 类
属性
| 资产 |
类型 |
Description |
| BluetoothAddressAsString |
字符串 |
获取此设备的蓝牙地址作为字符串 |
| BluetoothAddressAsUlong |
ulong |
获取此设备的蓝牙地址 |
| BluetoothLE设备(低功耗) |
BluetoothLE设备 |
获取此类封装的基本蓝牙设备 |
| DeviceInfo |
DeviceInformation |
获取此类包装的设备的设备信息 |
| ErrorText |
字符串 |
获取连接到此设备失败时的错误文本 |
| Glyph |
BitmapImage |
获取或设置此蓝牙设备的标志符号 |
| IsConnected |
布尔 |
获取一个值,该值指示此设备是否已连接 |
| 是否配对 |
布尔 |
获取一个值,该值指示此设备是否已配对 |
| Name |
字符串 |
获取此设备的名称 |
| RSSI |
int |
获取此设备的 RSSI 值 |
| Services |
ObservableCollection<ObservableGattDeviceService> |
获取此设备所支持的服务 |
| ServiceCount |
int |
获取或设置此设备具有的服务数 |
Methods
| Methods |
返回类型 |
Description |
| ConnectAsync() |
任务 |
将 ConnectAsync 连接到此蓝牙设备 |
| DoInAppPairingAsync() |
任务 |
应用程序内的配对功能正常吗? |
| UpdateAsync(DeviceInformationUpdate) |
任务 |
更新此设备的 deviceInformation |
| ToString() |
字符串 |
重写 ToString 函数以返回设备的名称 |
ObservableGattDeviceService
属性
| 资产 |
类型 |
Description |
| 特征 |
ObservableCollection<ObservableGattCharacteristics> |
获取此服务的所有属性 |
| Name |
字符串 |
获取此服务的名称 |
| 唯一通用识别码 (UUID) |
字符串 |
获取该服务的 UUID |
| 服务 |
GattDeviceService |
获取此类包装的服务 |
ObservableGattCharacteristics
属性
| 资产 |
类型 |
Description |
| 特征 |
GattCharacteristic(Gatt 特征) |
获取或设置此类封装的属性 |
| IsIndicateSet |
布尔 |
获取一个值,该值表明是否已设置指示器 |
| IsNotifySet |
布尔 |
获取一个值,该值指示是否已设置通知 |
| Parent |
ObservableGattDeviceService |
获取或设置此特征的父服务 |
| Name |
字符串 |
获取或设置此特征的名称 |
| 唯一通用识别码 (UUID) |
字符串 |
获取或设置此特性的 UUID |
| 价值 |
字符串 |
获取此特征的值 |
| DisplayType |
显示类型 |
获取或设置应如何显示此特征的值 |
Methods
| Methods |
返回类型 |
Description |
| ReadValueAsync() |
任务<字符串> |
读取特征的值 |
| SetIndicateAsync() |
任务<布尔> |
Set 的指示描述符 |
| StopIndicateAsync() |
任务<布尔> |
取消指示描述符 |
| SetNotifyAsync() |
任务<布尔> |
设置通知特征 |
| StopNotifyAsync() |
任务<布尔> |
移除通知描述符 |
Example
// Get a local copy of the context for easier reading
BluetoothLEHelper bluetoothLEHelper = BluetoothLEHelper.Context;
// check if BluetoothLE APIs are available
if (BluetoothLEHelper.IsBluetoothLESupported)
{
// Start the Enumeration
bluetoothLEHelper.StartEnumeration();
// At this point the user needs to select a device they want to connect to. This can be done by
// creating a ListView and binding the bluetoothLEHelper collection to it. Once a device is found,
// the Connect() method can be called to connect to the device and start interacting with its services
// Connect to a device if your choice
ObservableBluetoothLEDevice device = bluetoothLEHelper.BluetoothLeDevices[<Device you choose>];
await device.ConnectAsync();
// At this point the device is connected and the Services property is populated.
// See all the services
var services = device.Services;
}
' Get a local copy of the context for easier reading
Dim bluetoothLEHelper As BluetoothLEHelper = BluetoothLEHelper.Context
' check if BluetoothLE APIs are available
If BluetoothLEHelper.IsBluetoothLESupported Then
' Start the Enumeration
bluetoothLEHelper.StartEnumeration()
' At this point the user needs to select a device they want to connect to. This can be done by
' creating a ListView and binding the bluetoothLEHelper collection to it. Once a device is found,
' the Connect() method can be called to connect to the device and start interacting with its services
' Connect to a device if your choice
Dim device As ObservableBluetoothLEDevice = bluetoothLEHelper.BluetoothLeDevices(<Device you choose>)
Await device.ConnectAsync()
' At this point the device is connected and the Services property is populated.
' See all the services
Dim services = device.Services
End If
示例项目
BluetoothLE 帮助程序示例页面代码。 你可以在 Windows 社区工具包示例应用 中 看到此功能的实际操作。
要求
API