这是我的配对代码。
var Name = listBox1.SelectedItem as BluetoothLEDeviceDisplay;
DevicePairingResult result = await Name.DeviceInformation.Pairing.PairAsync();
updateUI("Paired.");我设置了我的"Name“来发现我的ble设备。
private void OnAdvertisementReceived(BluetoothLEAdvertisementWatcher watcher, BluetoothLEAdvertisementReceivedEventArgs eventArgs)
{
Name = eventArgs.Advertisement.LocalName;
if (items.Contains(Name) == false)
{
items.Add(Name);
}
}当我尝试配对BLE设备(Rfduino)时。我得到了error "<Name>5_1 is null"。我该如何解决这个问题?
发布于 2018-05-24 03:51:48
我确信你不需要配对你的设备。大多数,如果不是所有的Ble设备都不需要配对,除非你想要一个配对对话框来输入pin-number。
你的代码一点意义都没有。
BluetoothLEDeviceDisplay是一个单独的类,包含对象和枚举以便于显示,在一些UWP示例中使用。
因此作为选定项的名称将始终为空。
DeviceInformationCustomPairing customPairing = bleDeviceDisplay.DeviceInformation.Pairing.Custom;
DevicePairingKinds ceremoniesSelected = DevicePairingKinds.None | DevicePairingKinds.ProvidePin;
DevicePairingProtectionLevel protectionLevel = DevicePairingProtectionLevel.None;
customPairing.PairingRequested += new TypedEventHandler<DeviceInformationCustomPairing,
DevicePairingRequestedEventArgs>(CustomPairing_PairingRequested);
DevicePairingResult result = await customPairing.PairAsync(ceremoniesSelected,
protectionLevel);
private void CustomPairing_PairingRequested(DeviceInformationCustomPairing sender, DevicePairingRequestedEventArgs args)
{
//this is where your pin goes.
//windows requires at least a "0".
args.Accept("000000");//123456
}我在Windows10创建者更新之前使用过这个,但在那之后就再也没有使用过。看看我的Github示例,让您在不进行配对的情况下继续:https://github.com/GrooverFromHolland/SimpleBleExample_by_Devicename
https://stackoverflow.com/questions/50461451
复制相似问题