【问题标题】:How to access two different services from the same ble device如何从同一个 ble 设备访问两个不同的服务
【发布时间】:2016-11-01 08:56:49
【问题描述】:

例如,我有两个心率监测器与我的平板电脑配对。 我正在使用这样的代码来获取 HRM 设备列表:

var devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync
(
    GattDeviceService.GetDeviceSelectorFromUuid(GattServiceUuids.HeartRate)
);

然后我在 GUI 中显示一个列表框,其中设备名称来自 devices[i].Name。 例如,我选择索引为 0 的设备。然后我可以访问它 HR 服务和 HRM 特征:

var service = await GattDeviceService.FromIdAsync(devices[0].Id);
var characteristic = await service.GetCharacteristics(attCharacteristicUuids.HeartRateMeasurement);

除了心率,我还需要电池状态。如何访问同一(已选择)设备的电池服务?

【问题讨论】:

    标签: c# bluetooth-lowenergy windows-8.1


    【解决方案1】:

    开始之前的一些信息:

    您必须将蓝牙设备与计算机配对,然后才能扫描它们!

    Listing your paired devices:

    ListBox1.Items.Clear();
    
    var devices = await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort));
    
    foreach (var device in devices)
    {
        ListBox1.Items.Add(device);
    }
    

    如果您想知道蓝牙设备的电池寿命:

    How to get the battery level after connect to the BLE device?

    要同时访问多项服务,您需要“重新连接”到设备:

    设备A一次只能连接一个设备B上的服务S。设备A可以同时连接设备B、C、D和E等上的服务S。

    @alanjmcf

    来源:Establishing multiple bluetooth SPPs at the same time

    但不要与GetAllIncludedServices(); 方法混淆,因为它确实返回“包含的服务”。正如an other question 所述的一个答案:

    您可能不想获得“包含的服务”。包含的服务是 BLE 中的一个特殊概念,我怀疑您是否使用它来链接一个服务与另一个服务。

    @Emil

    【讨论】:

    • 设备已配对,设备列表没有问题。没有获得人力资源管理也没有问题。我在访问 ONCE 选定设备的 BOTH 服务时遇到问题。
    猜你喜欢
    • 1970-01-01
    • 2020-06-09
    • 2023-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-29
    相关资源
    最近更新 更多