连接到Windows 10上的BLE外围设备

连接到Windows 10上的BLE外围设备,windows,bluetooth,Windows,Bluetooth,我试着连接外设。首先,我看广告: watcher=new BluetoothLEAdvertisementWatcher{ScanningMode=BluetoothLesScanningMode.Active}; watcher.Received+=watcher-Received; watcher.Start(); 在Watcher回调中,我尝试创建BluetoothLEDevice 已接收到公共异步void watchen(Bluetooth LeadVertizedTwatcher发送

我试着连接外设。首先,我看广告:

watcher=new BluetoothLEAdvertisementWatcher{ScanningMode=BluetoothLesScanningMode.Active};
watcher.Received+=watcher-Received;
watcher.Start();
在Watcher回调中,我尝试创建BluetoothLEDevice

已接收到公共异步void watchen(Bluetooth LeadVertizedTwatcher发送方,Bluetooth Lead VertizeTreeEventArgs btAdv)
{
BluetoothLEDevice bleDevice=等待BluetoothLEDevice.FromBluetoothAddressAsync(btAdv.BluetoothAddress);
}
然而,我总是在收到的回调中得到bleDevice==null。为什么以及如何修复它?在UWP应用程序中创建BLE设备的正确方法是什么?然后,我需要连接到该设备,发现其GATT服务和特性,启用其中一些服务的通知,并读取/写入其中的一些。如果您希望能够连接到以前未配对的BLE设备,即使用带有蓝牙LE选择器的DeviceWatcher,请参见中的示例8和9

否则,您需要先在系统的蓝牙配对设置中对其进行配对,然后才能从bluetooth AddressAsync检索bluetooth设备。

如果您希望能够连接到以前未配对的可编程设备,即使用带有蓝牙LE选择器的DeviceWatcher,请参阅中的示例8和9


否则,您需要先在系统的蓝牙配对设置中对其进行配对,然后才能从BluetoothAddressAsync检索BluetoothLED设备。

您可以在
WatcherOnReceived()
中检查设备信息,以确保设备是您想要连接的设备。这样做:

public async void watcher已接收(BluetoothLeadVertizentWatcher发送方,BluetoothLeadVertizentReceivedEventArgs btAdv)
{
如果(btAdv.advision.LocalName==“SensorTag”)
{
BluetoothLEDevice bleDevice=等待BluetoothLEDevice.FromBluetoothAddressAsync(btAdv.BluetoothAddress);
}    
}
使用您自己的BLE设备名称,而不是“SensorTag”


注意:您需要事先配对您的可编程设备(可以像DeviceEnumeration和Pairing sample那样编程,也可以像下图所示的PC设置应用程序那样编程)

您可以在
WatcherOnReceived()
中检查设备信息,以确保该设备是您想要连接的设备。这样做:

public async void watcher已接收(BluetoothLeadVertizentWatcher发送方,BluetoothLeadVertizentReceivedEventArgs btAdv)
{
如果(btAdv.advision.LocalName==“SensorTag”)
{
BluetoothLEDevice bleDevice=等待BluetoothLEDevice.FromBluetoothAddressAsync(btAdv.BluetoothAddress);
}    
}
使用您自己的BLE设备名称,而不是“SensorTag”


注意:您需要事先配对您的可编程设备(可以像DeviceEnumeration和Pairing sample那样编程,也可以像下图所示的PC设置应用程序那样编程)

这个问题的答案很简单-不要在Windows 10上使用BLE。API不工作或行为随机,完全没有文档记录。我喜欢大家都在谈论物联网是下一次工业革命,而微软在6年后没有可工作的BLE API BLE存在。

这个问题的答案很简单-不要在Windows 10上使用BLE。API不工作或行为随机,完全没有文档记录。我喜欢大家谈论物联网是下一次工业革命,而微软在BLE存在6年后不再使用BLE API。

谢谢。在该示例的场景9中,我配对了我的BLE设备。现在,IsPaired标志在那个设备上显示为true。但我在我的应用程序中仍然得到bleDevice==null。一旦我在.FromBluetoothAddressAsync调用上收到异常0x80070490。广告查看器上似乎没有筛选器-您确定要连接的设备是您感兴趣的BLE设备吗?某些BLE设备不可连接,您只能从它们接收广告。因此蓝牙连接是由BluetoothLEDevice bleDevice=Wait BluetoothLEDevice.FromBluetoothAddressAsync(btAdv.BluetoothAddress)?是的,我确信这是我想要连接的设备,因为它是我附近唯一的可移动设备。谢谢。在该示例的场景9中,我配对了我的BLE设备。现在,IsPaired标志在那个设备上显示为true。但我在我的应用程序中仍然得到bleDevice==null。一旦我在.FromBluetoothAddressAsync调用上收到异常0x80070490。广告查看器上似乎没有筛选器-您确定要连接的设备是您感兴趣的BLE设备吗?某些BLE设备不可连接,您只能从它们接收广告。因此蓝牙连接是由BluetoothLEDevice bleDevice=Wait BluetoothLEDevice.FromBluetoothAddressAsync(btAdv.BluetoothAddress)?是的,我确定这是我想要连接的设备,因为它是我附近唯一的可编程设备。我可以看到,我的可编程设备从未显示在“设置->设备->蓝牙”中,即使PC正在搜索设备。但是,当我运行Windows平台示例(场景8或9)时,我可以看到该设备。设备已配对。我还可以在watcher中看到设备。但是FromBluetoothAddressAsync始终为设备返回null。@MartinDusek在
UpdatePairingButtons()之前添加以下代码
场景8\u配对设备的
配对按钮中单击()<代码>如果(dpr.Status==DevicePairingResultStatus.Paired){BluetoothLEDevice bleDevice=Wait BluetoothLEDevice.FromIdAsync(DeviceInfo Disp.DeviceInformation.Id);}
则运行场景8,对所选设备进行配对并检查连接状态。注意:连接设备需要一些时间。如果您在配对后立即检查
bleDevice
,它可能是
null
。谢谢您的建议。设备的计算结果仍然为n