简体   繁体   English

如何从C ++代码扫描并连接到广告BLE设备?

[英]How to scan and connect to advertising BLE devices from C++ code?

I'm trying to search and connect to advertising Bluetooth Low Energy devices from C++ code. 我正在尝试从C ++代码搜索并连接到广告低功耗蓝牙设备。 I would like a piece of code to use laptop's wireless chip to discover and connect to BLE devices, regardless of their GATT Services. 我想要一段代码来使用笔记本电脑的无线芯片来发现并连接到BLE设备,而不管它们的GATT服务如何。 I want in fine to use GATT properties (Services, Characteristics, Descriptors, Notification). 想蛮好用的GATT属性(服务,特点,描述符,通知)。

Programmatically 以编程方式

I have the BluetoothLEAdvertisementWatcher Class documentation from Windows API. 我有Windows API的BluetoothLEAdvertisementWatcher类文档。

I tried to make working this example but without good results. 我试图使这个例子工作,但没有取得好的结果。

I also tried this example , but no success. 我也尝试过这个例子 ,但没有成功。

Manually 手动地

I figured out using Windows 10 Action Center, and use manual pairing to connect devices (because Windows con see and connect my device). 我发现使用Windows 10操作中心,并使用手动配对来连接设备(因为Windows可以看到并连接我的设备)。

Then I could use directely the Windows.Devices.Bluetooth.GenericAttributeProfile Namespace 然后,我可以直接使用Windows.Devices.Bluetooth.GenericAttributeProfile命名空间

Is there a way to implement that automatically? 有没有一种方法可以自动实现?

Hello Raphaël and welcome to stackoverflow. 您好Raphaël,欢迎来到stackoverflow。 When you say "without good results" or "but no success", you should detail why (compilation error, runtime error...). 当您说“没有好的结果”或“但是没有成功”时,您应该详细说明原因(编译错误,运行时错误...)。

I used this piece of code: Getting BLE Beacons in C++ Windows 10 Desktop Application 我使用了这段代码: 在C ++ Windows 10桌面应用程序中获取BLE信标

It compiles under Win10, so should the third link you posted ( https://github.com/urish/win-ble-cpp ) as it's very similar if you look at the includes here. 它可以在Win10下编译,因此您发布的第三个链接( https://github.com/urish/win-ble-cpp )也应该如此,因为如果您在此处查看包含内容,则该链接非常相​​似。 Just note that this is not regular win32 projects: from Visual Studio you must create a new "Windows"/"Universal" C++ project, else they won't compile. 请注意,这不是常规的win32项目:在Visual Studio中,您必须创建一个新的“ Windows” /“ Universal” C ++项目,否则它们将无法编译。

Alternatively, if you're OK with using a 3rd party library, you could simply use QtBluetooth , recent version supports windows 10. Then you can easily access BLE features from aregular win32 project. 另外,如果您可以使用第3方库,则可以简单地使用QtBluetooth ,最新版本支持Windows10 。然后您可以轻松地从aregular win32项目中访问BLE功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM