BluetoothClient仅支持已配对的传统蓝牙设备发现,无法扫描未配对或BLE设备;搜不到设备需检查系统可见性、驱动状态及组策略限制。Windows 上用 BluetoothClient 搜不到设备?先确认平台限制在 .net framework 或 .net 5+ 的 windows 平台下,bluetoothclient 默认只支持 rfcomm 协议的配对设备发现,且严重依赖系统蓝牙协议栈(bth)是否启用"可被发现"模式。它根本不会扫描未配对、不可见或使用 ble(bluetooth low energy)广播的设备。常见错误现象:BluetoothClient.DiscoverDevices() 返回空数组,或抛出 SocketException 错误码 10013(权限拒绝)真实使用场景:仅适用于已手动配对、且对方设备处于"可见"状态的传统蓝牙(BR/EDR)设备,比如老式蓝牙打印机、串口模块关键参数差异:DiscoverDevices(int) 的参数是最大返回数量,不是超时毫秒数;超时由底层驱动控制,无法通过 API 调整兼容性影响:.NET Core / .NET 5+ 在 Windows 上仍可用该类,但 Linux/macOS 完全不支持 ------ PlatformNotSupportedException 会直接抛出想扫 BLE 设备?必须换 Windows.Devices.Bluetooth.AdvertisementWindows 10 1809+ 系统原生支持 BLE 广播监听,但需要 UWP 运行时能力(即使你写的是 WinForms/WPF,也得走 WindowsRuntimeComponent 或启用 C++/CX 互操作),而且必须声明 bluetooth 功能权限。常见错误现象:调用 BluetoothLEAdvertisementWatcher.Start() 后无回调,或触发 Stopped 事件并带 BluetoothLEAdvertisementWatcherStatus.DisabledByUser必须做的三件事:-- 在 Package.appxmanifest(或项目属性 > 功能)中勾选 bluetooth-- 运行时检查 BluetoothAdapter.GetDefaultAsync() 是否返回非 null-- 用户需在系统设置中打开"蓝牙"和"允许设备通过蓝牙查找此设备"(后者影响接收广播)性能注意点:ScanningMode 设为 Active 才能收到扫描响应(Scan Response),但耗电更高;Passive 模式只收广播包(Advertising Data),适合低功耗监听WinForms/WPF 项目里怎么安全接入 UWP 蓝牙 API?不能直接引用 Windows.Devices.Bluetooth 命名空间到传统桌面项目,必须通过 .NET 5+ 的"Windows Runtime Support"桥接,或者用 Microsoft.Windows.SDK.Contracts NuGet 包(仅限 Windows 10 1809+)。 文心快码 文心快码(Comate)是百度推出的一款AI辅助编程工具
相关推荐
金銀銅鐵10 小时前
用 Python 实现 Take-Away 游戏copyer_xyf11 小时前
Agent 流程编排copyer_xyf11 小时前
Agent RAGcopyer_xyf11 小时前
【RAG】向量数据库:milvuscopyer_xyf12 小时前
Agent 记忆管理星云穿梭1 天前
用Python写一个带图形界面的学生管理系统——完整教程金銀銅鐵1 天前
用 Pygame 实现 15 puzzle倔强的石头_1 天前
《Kingbase护城河》——数据库存储空间全景探测与精细化瘦身实战黄忠1 天前
大模型之LangGraph技术体系冬奇Lab2 天前
每日一个开源项目(第134篇):Zvec - 阿里开源的嵌入式向量数据库,向量搜索界的 SQLite