蓝牙LE服务在C#Windows Store应用程序中没有为已知特性返回任何内容?

时间:2014-05-09 15:14:12

标签: c# bluetooth windows-store-apps characteristics

我有一个C#Windows应用商店应用,可与自定义蓝牙低功耗设备连接。我能够枚举设备,连接设备,成功发送验证密钥,并获得设备加速度计的特性。但是,当我尝试获取X轴特征的特征时,服务的GetCharacteristics()枚举器返回一个空列表。我肯定在我的包清单中声明了X轴特征的UUID。我已经阅读了设备上的论坛,因此我知道Android用户可以访问它。但出于某种原因,我无法做到。

是否有人遇到此问题并知道如何修复它?

这是我的宣言:

    <!-- V.BTTN Accelerometer configuration characteristic -->
    <m2:Function Type="serviceId:fffffff2-00f7-4000-b000-000000000000" />

    <!-- V.BTTN Accelerometer X-Axis notification characteristic -->
    <m2:Function Type="serviceId:ffffffA3-00f7-4000-b000-000000000000" />
    <!-- V.BTTN Accelerometer Y-Axis notification characteristic -->
    <m2:Function Type="serviceId:ffffffA4-00f7-4000-b000-000000000000" />
    <!-- V.BTTN Accelerometer Z-Axis notification characteristic -->
    <m2:Function Type="serviceId:ffffffA5-00f7-4000-b000-000000000000" />

这是我访问主加速度计配置特性并试图获得X轴特性的代码:

    // <!-- V.BTTN Accelerometer X-Axis notification characteristic -->
    public static Guid vbttnAccelerometerXAxisNotify_uuid = new Guid("ffffffA3-00f7-4000-b000-000000000000");

    // <!-- V.BTTN Accelerometer Y-Axis notification characteristic -->
    public static Guid vbttnAccelerometerYAxisNotify_uuid = new Guid("ffffffA4-00f7-4000-b000-000000000000");

    // <!-- V.BTTN Accelerometer Z-Axis notification characteristic -->
    public static Guid vbttnAccelerometerZAxisNotify_uuid = new Guid("ffffffA5-00f7-4000-b000-000000000000");


    private GattCharacteristic GetCharacteristicByIdAndNdx(Guid characteristicUuid, int ndx = 0)
    {
        if (characteristicUuid == Guid.Empty)
            throw new ArgumentNullException("The characteristic ID is empty.");

        if (ndx < 0)
            throw new ArgumentOutOfRangeException("The characteristic is negative.");

        // Obtain the accelerometer configuration characteristic.
        IReadOnlyList<GattCharacteristic> iroCharacteristics =
            VAlertService.Instance.Service.GetCharacteristics(characteristicUuid);

        if (iroCharacteristics.Count < 1)
            throw new InvalidOperationException("Unable to find the V.ALRT characteristic with the given UUID and index.");

        if (ndx >= iroCharacteristics.Count)
            throw new InvalidOperationException("Found the desired V.ALRT characteristic but the index is out of range.");

        return iroCharacteristics[ndx];
    }

            // < snip >
            // Obtain the accelerometer configuration characteristic.
            this._accelerometerConfigCharacteristic = GetCharacteristicByIdAndNdx(vbttnAccelerometerConfigCharacteristic_uuid);

            // Enable the accelerometer.
            if (!(await this.SetAccelerometerMode(true)))
                throw new InvalidOperationException("Unable to enable the V.ALRT accelerometer characteristic.");

            GattCharacteristic this._accelerometerXAxisCharacteristic = GetCharacteristicByIdAndNdx(vbttnAccelerometerXAxisNotify_uuid);
            GattCharacteristic this._accelerometerYAxisCharacteristic = GetCharacteristicByIdAndNdx(vbttnAccelerometerYAxisNotify_uuid);
            GattCharacteristic this._accelerometerZAxisCharacteristic = GetCharacteristicByIdAndNdx(vbttnAccelerometerZAxisNotify_uuid);

0 个答案:

没有答案