0

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

这是原型。这不是一个静态函数,这可能与这里有关。谢谢你的帮助。

4

0 回答 0