2015-12-27 57 views
5

Windows 10のIoTですべてのMACアドレスを読み取るアプリケーションを作成しようとしています。これらのコード行は、接続されていないすべてのデバイスがオンになっていなくても戻しています。Windows10でのBluetooth MACアドレスの検索ペアなしのUWP

var selector = BluetoothDevice.GetDeviceSelector(); 
var devices = await DeviceInformation.FindAllAsync(selector); 
listBox.Items.Add(devices.Count); 
foreach (var device in devices) 
{ 
    listBox.Items.Add(device.Id); 
} 

そして私もかかわらず、コード

await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort)); 

これ返すヌルのこのラインを見つけました。 Windows 10のユニバーサルアプリケーションですべてのMACアドレスをスキャンする方法はありますか?

答えて

1

質問の回答を見つけるのはとても近くです。 DeviceIdプロパティからBluetoothDeviceインスタンスを取得してみてください。その後、周りのすべてのBluetooth LEデバイスをスキャンするBluetoothLEAdvertisementWatcherを使用して、新しいアプローチがありますBluetoothアドレス

var selector = BluetoothDevice.GetDeviceSelector(); 
var devices = await DeviceInformation.FindAllAsync(selector); 
foreach (var device in devices) 
{ 
    var bluetoothDevice = await BluetoothDevice.FromIdAsync(device.Id); 
    if (bluetoothDevice != null) 
    { 
     Debug.WriteLine(bluetoothDevice.BluetoothAddress); 
    } 
    Debug.WriteLine(device.Id); 
    foreach(var property in device.Properties) 
    { 
     Debug.WriteLine(" " + property.Key + " " + property.Value); 
    } 
} 
+0

アプリケーションはまだ既にペアリングされているデバイスのみを創立: は、ここで私は私のプロジェクトで使用するコードの一部です。ペアリングせずにMACアドレスを見つける方法はありますか? –

+0

いいえ、実際にはできません。 – danvy

+0

でも、ペアリングされたデバイスはどのように見つけられますか?デバイスの範囲内にあるデバイスはどれですか?ペアになったすべてのデバイスを作成するこのコード行を取得します。 –

2

を含むすべての特定のBluetoothの情報を取得することができます。

var advertisementWatcher = new BluetoothLEAdvertisementWatcher() 
{ 
    SignalStrengthFilter.InRangeThresholdInDBm = -100, 
    SignalStrengthFilter.OutOfRangeThresholdInDBm = -102, 
    SignalStrengthFilter.OutOfRangeTimeout = TimeSpan.FromMilliseconds(2000) 
}; 

advertisementWatcher.Received += AdvertisementWatcher_Received; 
advertisementWatcher.Stopped += AdvertisementWatcher_Stopped; 

advertisementWatcher.Start(); 

以降

advertisementWatcher.Stop(); 

advertisementWatcher.Received -= AdvertisementWatcher_Received; 
advertisementWatcher.Stopped -= AdvertisementWatcher_Stopped; 
関連する問題