2

我有一个与自定义蓝牙低功耗设备接口的 C# Windows Store 应用程序。我能够枚举设备,连接到它,成功发送验证密钥,并获取设备加速度计的特征。但是,当我尝试获取 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);
4

0 回答 0