无用户引脚输入的无头UWP蓝牙配对

问题描述 投票:0回答:1

我目前正在构建一个运行在Windows 10 IoT核心版上的无头UWP应用。我需要能够通过蓝牙(RFCOMM)将移动设备连接到信息亭以收集数据。我需要能够从移动设备启动配对。

我已经尝试了所有UWP Bluetooth sample apps,但是大部分都已经尝试了Device Enumeration and Pairing C# sample-特别是方案9-自定义设备配对。我可以使用引脚成功配对到带头UWP应用程序,但无法成功配对无头UWP应用程序-尝试启动配对时,我得到“失败”结果或“身份验证超时”结果。

一对如何与没有UI的无头UWP应用配对以获取图钉?对于每次配对尝试,我都可以使用UWP应用程序使用硬编码的引脚而不是随机的引脚,但是我不确定这是否可行?

c# uwp bluetooth headless windows-10-iot-core
1个回答
0
投票

您可以尝试以下代码。当有传入的配对请求时,将调用handlerUpdater。

            handlerUpdated = new TypedEventHandler<DeviceWatcher, DeviceInformationUpdate>(async (watcher, deviceInfoUpdate) =>
            {
                // Since we have the collection databound to a UI element, we need to update the collection on the UI thread.
                await MainPage.Current.UIThreadDispatcher.RunAsync(CoreDispatcherPriority.Low, async () =>
                {
                    // Find the corresponding updated DeviceInformation in the collection and pass the update object
                    // to the Update method of the existing DeviceInformation. This automatically updates the object
                    // for us.
                    foreach (BluetoothDeviceInformationDisplay deviceInfoDisp in bluetoothDeviceObservableCollection)
                    {
                        if (deviceInfoDisp.Id == deviceInfoUpdate.Id)
                        {
                            if (deviceInfoDisp.DeviceInformation.Pairing.CanPair)
                            {
                                await deviceInfoDisp.DeviceInformation.Pairing.Custom.PairAsync(DevicePairingKinds.ConfirmOnly);
                            }

                            deviceInfoDisp.Update(deviceInfoUpdate);
                            break;
                        }
                    }
                });
            });
            deviceWatcher.Updated += handlerUpdated;
© www.soinside.com 2019 - 2024. All rights reserved.