如何正确调用GetGattServicesForUuidAsync?

时间:2018-06-21 21:13:18

标签: c++ windows bluetooth windows-runtime c++-winrt

我很难从设备上获得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);

Here's原型。这不是静态函数,在这里可能需要做一些事情。感谢您的帮助。

0 个答案:

没有答案