通过GetCharacteristicsAsync访问拒绝状态以获取定制服务的特征

时间:2018-06-25 13:23:45

标签: c# wpf uwp bluetooth-lowenergy .net-standard

我正在尝试获取自定义BLE服务的特征。我有一个NETStandard类库,它利用NETCore build 17134进行蓝牙通信。然后,可以在WPF应用程序(.NET Framework 4.7.1。)中使用该库。我可以连接到BLE外围设备,还可以读取包括硬件修订版等的常规服务。但是,当它转到获取我的自定义服务的特征,状态读取为AccessDenied,特征数组为空。任何帮助将不胜感激。

当纯UWP时,相同的代码也可以工作。但是,我无法像在UWP中那样在桌面应用程序中设置蓝牙权限。我试图以管理员身份运行并使用AppID /注册表项执行解决方法。它似乎没有用,但也许我只是做错了什么。

这是一个已知问题吗?我已经读过,自最初的Creator's Update(15xxx)以来,已有一些回归,但是所有线程似乎都已经使用了一年。

    protected async override Task<IList<ICharacteristic>> GetCharacteristicsNativeAsync()
    {
        var accessRequestResponse = await _nativeService.RequestAccessAsync();

        // Returns Allowed
        if (accessRequestResponse != Windows.Devices.Enumeration.DeviceAccessStatus.Allowed)
        {
            throw new Exception("Access to service " + _nativeService.Uuid.ToString() + " was disallowed w/ response: " + accessRequestResponse);
        }

        var allCharacteristics = await _nativeService.GetCharacteristicsAsync(Windows.Devices.Bluetooth.BluetoothCacheMode.Uncached);
        // Status: AccessDenied
        var status = allCharacteristics.Status;

        // No error
        var err = allCharacteristics.ProtocolError;
        var nativeChars = allCharacteristics.Characteristics;
        var charList = new List<ICharacteristic>();

        foreach (var nativeChar in nativeChars)
        {
            var characteristic = new Characteristic(nativeChar, this);
            charList.Add(characteristic);
        }

        return charList;
    }

任何帮助将不胜感激!

0 个答案:

没有答案