uwp - DeviceWatcher 和 BluetoothLEAdvertisementWatcher 类和 Timeout 属性之间的区别

标签 uwp timeout connection bluetooth-lowenergy ads

我构建了一个 Windows 10 应用程序,用于监视特定广告并与之连接。

我用了例子 "BluetoothLE" from "Windows-universal-samples"稍作编辑。在这个例子中,他们使用了“DeviceWatcher”类。

但我现在正尝试添加超时以在特定时间段后断开连接。 我发现这个属性:OutOfRangeTimeout 属于 BluetoothLEAdvertisementWatcher 类。

现在我很困惑“DeviceWatcher”和“BluetoothLEAdvertisementWatcher”之间有什么区别?

有没有办法使用 DeviceWatcher 类添加“超时”?

最佳答案

“DeviceWatcher”类和 BluetoothLEAdvertisementWatcher 类之间有很大区别。 deviceWacher 是系统级的;这意味着您必须先在 Windows 设置中添加该设备,然后才能找到它。这也意味着该设备始终存在于 Windows.Devices.Enumeration 中,除非您将其从 Windows 设置中删除。设备观察器需要很长时间才能完成。此外,为了制作一个运行良好的应用程序,您必须实现所有添加、删除和更新事件,以便在有设备添加、删除或更新时得到通知。如果应用仅处理添加的事件,则在初始设备枚举完成后将设备添加到系统时,它不会收到更新。

BluetoothLEAdvertisementWatcher 仅监听发送广告且触手可及的 BLE 设备。如果您将 scanMode 设置为事件状态,观察者会尝试获取设备上的所有信息,例如名称、功能、ble-Address、服务广告负载等。将其设置为 scanMode passive,watcher 只监听使用 name 和 Ble-address 的设备,速度更快。

扫描时间仅取决于范围内的设备数量及其广告间隔。 OutOfRangeTimeout 指的是决定设备是否超出范围的 BluetoothSignalStrengthFilter

关于断开连接的超时时间:

蓝牙 LE 设备 API 不提供对设备连接的直接控制。相反,如果没有未完成的引用,蓝牙堆栈将在一秒超时后断开设备。所以你必须使用计时器来设置你的超时时间并关闭和处理设备!

关于uwp - DeviceWatcher 和 BluetoothLEAdvertisementWatcher 类和 Timeout 属性之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50210211/

相关文章:

c++ - 检测远程桌面连接何时启动?

uwp - 将 ItemsSource 更新为 ItemsControl 时,SelectedItem 选择丢失

wpf - 如何更改 Xaml AppBarButton (Windows UWP) 的标签位置

iphone - ASIHTTP请求超时

python - python 的 SSH 模块

connection - typeorm getConnection() 找不到 "default"连接

C# - 从客户端检查 TCP/IP 套接字状态

android - 使用 Xamarin Forms nuget Xam.Plugin.Media 用相机拍照

c# - Json 文件的 FileStream 初始化抛出 System.NotSupportedException

javascript - 取消为一个 ID 设置的多个超时