获取设备的蓝牙版本

时间:2021-01-07 20:02:13

标签: c# .net uwp bluetooth windows-10

我需要验证蓝牙 LE 5.0 设备是否已连接到计算机。我一直在查看可以查询设备的所有属性,但没有找到包含该设备蓝牙版本的属性。这可以使用 UWP 或任何其他方法完成吗?

这是我用来探索使用 UWP 可以获得的数据的代码:

string aqsFilter = "System.Devices.DevObjectType:=5 AND (System.Devices.Aep.ProtocolId:=\"{BB7BB05E-5972-42B5-94FC-76EAA7084D49}\" OR System.Devices.Aep.ProtocolId:=\"{E0CBF06C-CD8B-4647-BB8A-263B43F0F974}\") AND (System.Devices.Aep.IsConnected:=System.StructuredQueryType.Boolean#True OR System.Devices.Aep.Bluetooth.IssueInquiry:=System.StructuredQueryType.Boolean#False)";
        string[] requestedProperties = {
            "System.Devices.Aep.Category",
            "System.DeviceInterface.Bluetooth.DeviceAddress",
            "System.DeviceInterface.Bluetooth.Flags",
            "System.Devices.Aep.Bluetooth.Le.AddressType",
            "System.Devices.Aep.Bluetooth.Le.Appearance",
            "System.Devices.Aep.Bluetooth.Le.Appearance.Category",
            "System.Devices.Aep.Bluetooth.Le.Appearance.Subcategory",
            "System.Devices.Aep.DeviceAddress",
            "System.Devices.AepService.ServiceClassId",
            "System.Devices.Aep.ProtocolId",
            "System.Devices.AepService.ProtocolId"
        };
        DeviceInformationCollection ConnectedBluetoothDevices = await DeviceInformation.FindAllAsync(aqsFilter, requestedProperties); //aqsFilter

        foreach (DeviceInformation connectedBluetoothDevice in ConnectedBluetoothDevices)
        {
            Console.WriteLine(connectedBluetoothDevice.Name);
            Console.WriteLine("  " + connectedBluetoothDevice.Id);
            Console.WriteLine("  " + connectedBluetoothDevice.Kind.ToString());
            Console.WriteLine("  " + connectedBluetoothDevice.Properties.Count);

            foreach (KeyValuePair<string, object> property in connectedBluetoothDevice.Properties)
            {
                if (property.Value != null && property.Value.GetType().IsArray)
                {
                    String[] array = (String[])property.Value;
                    Console.WriteLine("    " + property.Key + " = " + array[0]);
                }
                else
                {
                    Console.WriteLine("    " + property.Key + " = " + property.Value);
                }
            }
        }

0 个答案:

没有答案
相关问题