Windows UWP Bluetooh 多个设备显示为单个设备

Windows UWP Bluetooh multiple devices showing for single device

我目前正在开发一个 C#-UWP 应用程序,该应用程序需要能够发现网络上的蓝牙设备(非 BLE)以及之前已连接的设备 to/paired。

我相信任何不熟悉此任务的人都会很快发现文档和示例几乎没有帮助。我从有关人们实验的 Whosebug 问题中学到的知识比从文档和示例中学到的更多,但无论如何。

我的主要 question/problem 是这样的: 在设置设备观察器以查找蓝牙设备后,我发现我一直收到同一设备的多个添加,但有一个不同的蓝牙地址(这是以前配对但不在网络上的设备)。经过大量调查和头脑风暴,我们发现每个设备 ID 实际上是设备 MAC 地址和 BT 接收器 MAC 地址的配对。

我每 1 个物理设备添加 3 个设备的原因是因为我过去曾使用 3 个不同的 BT 接收器加密狗连接到同一个设备。所以我的问题是,有没有办法让设备观察器 return 成为与当前活动的 BT 接收器加密狗相对应的设备?

否则我将需要找到当前活动的 BT 接收器 MAC 地址并过滤掉没有此地址的设备,否则用户将看到 3 个与 select 相同的设备并且只有其中 1 个将通过,而其他 2 个将失败。

关于这个主题,我还想提一下设备属性似乎不起作用。在创建观察者之前,我有一个这样的属性列表,例如:

requestedProperties.Add("System.Devices.Aep.DeviceAddress");
requestedProperties.Add("System.Devices.Aep.IsConnected");
requestedProperties.Add("System.Devices.Aep.Bluetooth.Le.IsConnectable");
requestedProperties.Add("System.Devices.Aep.IsPresent");
requestedProperties.Add("System.Devices.Aep.ContainerId");
requestedProperties.Add("System.Devices.Aep.ModelId");
requestedProperties.Add("System.Devices.Aep.Manufacturer");
requestedProperties.Add("System.Devices.Aep.ProtocolId");
requestedProperties.Add("System.Devices.Aep.SignalStrength");

但是当我调试添加的设备时,它没有任何属性: debug info showing no properties for added device

如果我有这些信息会很有用。

感谢您的任何意见或建议。

更新

我找到了一个解决这个问题的快速解决方案(虽然我确实发现了更多关于设备观察器的问题,但这可能是另一个问题的主题)。

现在我只是获取当前的 BT 适配器 MAC 地址,然后检查每个传入设备是否在其对中具有此 MAC 地址。如果没有,则表示设备已与 old/unused BT 适配器配对。

/*  NOTE:
Windows allows only 1 BT adapter to be active on 1 machine at a time
Therefore this function will either return the active dongle or a null if 
there is no BT adapter on the machine or its disabled.
*/
BluetoothAdapter BTAdaptor = await BluetoothAdapter.GetDefaultAsync();

if (BTAdaptor == null)
{
   // Log error
   // return
}

//
// Code block to check if the BT adaptor can support the BT tech stack you are interested in.
//

// Format into hex with 12 characters (12 being the number of characters for MAC address)
string tempMac = BTAdaptor.BluetoothAddress.ToString("X12").ToLower();

// Pattern for MAC address.
string pattern = "(.{2})(.{2})(.{2})(.{2})(.{2})(.{2})";
string replace = ":::::";

m_strBTAdapterMAC = Regex.Replace(tempMac, pattern, replace);

然后当设备被观察者事件 added/updated/removed 时,检查它:

// If device is not paired with the currently used BT adapter. 
if (deviceInfo.Id.Contains(m_strBTAdapterMAC) == false)
{
     // Device paired with old dongle, dont want to show the user.
     return;
}

如果有人想出如何让设备观察器不提供旧设备,请告诉我,这可能是更好的解决方案。