BLE広告をスキャンできるプログラムを作成しようとしています。私は、Windows Universalサンプル、より正確にはBluetoothAdvertisementというサンプルを見てきました。私は、BLE広告をスキャンしてリストボックスに表示できるシンプルなUWPアプリケーションを作成したいと考えています。しかし、私のアプリケーションは全く何も見つけることができず、私は完全に失われています。BLE広告UWPアプリケーション
namespace BleDiscAdv2
{
public sealed partial class MainPage : Page
{
// The Bluetooth LE advertisement watcher class is used to control and customize Bluetooth LE scanning.
private BluetoothLEAdvertisementWatcher watcher;
public MainPage()
{
this.InitializeComponent();
// Create and initialize a new watcher instance.
watcher = new BluetoothLEAdvertisementWatcher();
//Set the in-range threshold to -70dBm. This means advertisements with RSSI >= -70dBm
//will start to be considered "in-range"
watcher.SignalStrengthFilter.InRangeThresholdInDBm = -70;
// Set the out-of-range threshold to -75dBm (give some buffer). Used in conjunction with OutOfRangeTimeout
// to determine when an advertisement is no longer considered "in-range"
watcher.SignalStrengthFilter.OutOfRangeThresholdInDBm = -75;
// Set the out-of-range timeout to be 2 seconds. Used in conjunction with OutOfRangeThresholdInDBm
// to determine when an advertisement is no longer considered "in-range"
watcher.SignalStrengthFilter.OutOfRangeTimeout = TimeSpan.FromMilliseconds(2000);
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
// Attach a handler to process the received advertisement.
// The watcher cannot be started without a Received handler attached
watcher.Received += OnAdvertisementReceived;
}
private void btStart_Click(object sender, RoutedEventArgs e)
{
watcher.Start();
}
private async void OnAdvertisementReceived(BluetoothLEAdvertisementWatcher watcher, BluetoothLEAdvertisementReceivedEventArgs eventArgs)
{
DateTimeOffset timestamp = eventArgs.Timestamp;
string localName = eventArgs.Advertisement.LocalName;
await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,() =>
{
lbModtaget.Items.Add("Name of device: " + localName + "\t" + "Time for advertisement: " + timestamp.ToString("hh\\:mm\\:ss\\.fff"));
});
}
}
}
誰かが間違っていることを教えてもらえますか? 私はBLEを初めて使用しているので、しばらくコーディングしていません。
敬具 クリスチャン
「DisabledByUser」というエラーは何を意味していますか?フォアグラウンドウォッチャーの例を実行しようとすると、これが表示されます。 – TedMilker
他の人に自分自身の質問に答える:「設定されていないデバイスと通信する」が「設定」 - >「プライバシー」 - >「他のデバイス」でオフになっていました – TedMilker