c++ - 如何正确调用 GetGattServicesForUuidAsync?
问题描述
我很难从我的设备上获得 GATT 服务。我正在使用 Visual Studio 2017,创建一个 C++/WinRT 控制台应用程序。到目前为止,我有这个代码:
struct Console
{
/* Create a watcher */
BluetoothLEAdvertisementWatcher watcher = BluetoothLEAdvertisementWatcher();
void Initialize()
{
watcher.ScanningMode(BluetoothLEScanningMode::Active);
watcher.Received({ this, &Console::OnAdvertisementReceived });
watcher.Start();
}
void OnAdvertisementReceived(BluetoothLEAdvertisementWatcher const& _watcher, BluetoothLEAdvertisementReceivedEventArgs const& args)
{
hstring bleDeviceName = L"xxx";
BluetoothLEAdvertisement adv = args.Advertisement();
if (adv.LocalName() == bleDeviceName) {
_watcher.Stop();
winrt::Windows::Foundation::IAsyncOperation device = BluetoothLEDevice::FromBluetoothAddressAsync(args.BluetoothAddress());
if (device != NULL) {
winrt::Windows::Foundation::IAsyncOperation servicesIncluded = BluetoothLEDevice::GetGattServicesForUuidAsync(MyService_GUID);
}
}
else cout << "No device found " << endl;
}
};
int main()
{
Console test;
test.Initialize();
cin.get();
return 0;
}
我无法让这个功能工作:
winrt::Windows::Foundation::IAsyncOperation servicesIncluded = BluetoothLEDevice::GetGattServicesForUuidAsync(MyService_GUID);
这是原型。这不是一个静态函数,这可能与这里有关。谢谢你的帮助。
解决方案
推荐阅读
- java - 可调用的 Guice DI
- python - actix Actor 如何拥有 PyO3 Python?
- c++ - 我可以从第三个线程监控 boost::lockfree::spsc_queue 吗?
- css - angular-gridster2 网格大小
- c# - Azure Durable 编排功能触发两次
- r - 使用 for 循环创建包含其他列中值计数的列
- html - 如何从 div 中减去形状?
- wordpress - 如何更改基于 Woocommerce 的网站中的特定 URL?
- angular - mat-accordion 扩展面板未显示在 mat-grid-list 中
- mongodb - mongodb聚合中的项目嵌套嵌入文档