首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >c#蓝牙乐写配置错误- ValueChanged从未调用

c#蓝牙乐写配置错误- ValueChanged从未调用
EN

Stack Overflow用户
提问于 2017-09-11 20:12:53
回答 2查看 965关注 0票数 0

因此,我尝试将我的c# WPF程序连接到一个BLE设备,这是连接到该设备的代码:

代码语言:javascript
运行
复制
private async Task ConnectToWatcher(DeviceInformation deviceInfo) {
        try {
            // get the device
            BluetoothLEDevice device = await BluetoothLEDevice.FromIdAsync(deviceInfo.Id);

            // get the GATT service
            Thread.Sleep(150);
            var gattServicesResult = await device.GetGattServicesForUuidAsync(new Guid(RX_SERVICE_UUID));
            service = gattServicesResult.Services[0];

            // get the GATT characteristic
            Thread.Sleep(150);
            var gattCharacteristicsResult = await service.GetCharacteristicsForUuidAsync(new Guid(RX_CHAR_UUID));
            characteristic = gattCharacteristicsResult.Characteristics[0];

            // register for notifications
            Thread.Sleep(150);

            characteristic.ValueChanged += (sender, args) => {
                Debug.WriteLine($"[{device.Name}] Received notification containing {args.CharacteristicValue.Length} bytes");
            };

            GattWriteResult result =
            await characteristic.WriteClientCharacteristicConfigurationDescriptorWithResultAsync(GattClientCharacteristicConfigurationDescriptorValue.Notify);
            Debug.WriteLine($"Characteristics write result: status={result.Status}, protocolError={result.ProtocolError}");

        } catch (Exception ex) when ((uint)ex.HResult == 0x800710df) {
            Debug.WriteLine("bluetooth error 1");
            // ERROR_DEVICE_NOT_AVAILABLE because the Bluetooth radio is not on.
        }
    }

线

代码语言:javascript
运行
复制
 Debug.WriteLine($"Characteristics write result: status={result.Status}, protocolError={result.ProtocolError}"

创建输出特性写结果: status=protocolError,protocolError=3 --我在任何地方都找不到这意味着什么。其结果是characteristic.ValueChanged从未被调用的方法。

我需要做更多的工作才能有特色的配置吗?有没有人知道为什么不调用该方法,或者该错误消息意味着什么?

谢谢一堆。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-09-14 17:22:41

显然,一些Windows 10版本存在COM安全漏洞。解决方案是注册Windows-内部程序和更新Windows.

Update:还有两种解决方案: 1)从c#-代码外部调用CoInitializeSecurity (没有使其工作)-或- 2)将两个新键写入windows注册表。您可以创建一个名为"Bluetooth.reg“的文件,它会将这两个键添加到一个双重键上。来自https://social.msdn.microsoft.com/Forums/en-US/58da3fdb-a0e1-4161-8af3-778b6839f4e1/bluetooth-bluetoothledevicefromidasync-does-not-complete-on-10015063?forum=wdk的这个答案是我的解决方案:

嗨,卡门,我也经历过同样的事情。您可以快速尝试以下几点:

Windows注册表编辑器5.00版

HKEY_LOCAL_MACHINE\SOFTWARE\Classes\AppID{C6BFD646-3DF0-4DE5-B7AF-5FFFACB844A5} "AccessPermission"=hex:01,00,04,80,9c,00,00,00,ac,0000000000000000001400 00,00,02,00,88,00,06,00,00,00,00,00,14,00,07,00,00,00,01,01,00,00,00,00,00,\ 05,0a,00,00,00,00,00,14,00,03,00,00,00,01,01,00,00,00,00,00,05,12,00,00,00,\ 00,00,18,00,07,00,00,00,01,02,00,00,00,00,00,05,20,00,00,00,20,02,00,00,00,\ 00,18,00,03,00,00,00,01,02,00,00,00,00,00,0f,02,00,00,00,01,00,00,00,00,00,\ 14,00,03,00,00,00,01,01,00,00,00,00,00,05,13,00,00,00,00,00,14,00,03,00,00,\ 00,01,01,00,00,00,00,00,05,14,00,00,00,01,02,00,00,00,00,00,05,20,00,00,00,\ 20,02,00,00,01,02,00,00,00,00,00,05,20,00,00,00,20,02,00,00

HKEY_LOCAL_MACHINE\SOFTWARE\Classes\AppID\YOURAPP.exe "AppID"="{C6BFD646-3DF0-4DE5-B7AF-5FFFACB844A5}“

  1. 将上述内容复制到文本文件中。
  2. 用可执行文件名替换“YOURAPP.EXE”
  3. 可以选择替换GUID(我为您创建了一个新的GUID)
  4. 将扩展名为.reg的文本文件保存为
  5. 双击文件。
  6. 您将看到一条消息:“包含在.reg中的密钥和值已成功地添加到注册表中。”

这样,我就不需要从我的应用程序中调用CoInitializeSecurity了。

票数 2
EN

Stack Overflow用户

发布于 2017-10-23 10:23:14

你得先打电话给CoInitializeSecurity

这里有更多信息。我花了几周时间寻找解决方案:)

https://social.msdn.microsoft.com/Forums/en-US/58da3fdb-a0e1-4161-8af3-778b6839f4e1/

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46163685

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档