/// <summary> /// Gets all devices based on their pairing state. Takes much longer to find unpaired devices than paired devices /// </summary> /// <param name="Connected">True to look for paired devices, false to look for unpaired devices</param> public static void DevicesWithPairingStatus(bool Paired) { CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { List <GattDevice> returnDevices = new List <GattDevice>(); string filter = BluetoothLEDevice.GetDeviceSelectorFromPairingState(Paired); DeviceInformationCollection infos = await DeviceInformation.FindAllAsync(filter); if (infos.Count > 0) { Debug.Log("Found " + infos.Count + " Devices"); foreach (DeviceInformation info in infos) { string deviceID = info.Id; Debug.Log("Device Name: " + info.Name); try { BluetoothLEDevice device = await BluetoothLEDevice.FromIdAsync(deviceID); GattDevice d = GattDevice.Create(device); returnDevices.Add(d); } catch { } } } OnDevicesAcquired?.Invoke(returnDevices); } ); }
private void ScanButton_Click(object sender, RoutedEventArgs e) { // Query for extra properties you want returned string[] requestedProperties = { "System.Devices.Aep.DeviceAddress", "System.Devices.Aep.IsConnected" }; //var deviceWatcher= new BluetoothLEAdvertisementWatcher { ScanningMode = BluetoothLEScanningMode.Active }; deviceWatcher = DeviceInformation.CreateWatcher( BluetoothLEDevice.GetDeviceSelectorFromPairingState(false), null, DeviceInformationKind.AssociationEndpoint); // Register event handlers before starting the watcher. // Added, Updated and Removed are required to get all nearby devices deviceWatcher.Added += DeviceWatcher_Added; deviceWatcher.Updated += DeviceWatcher_Updated; deviceWatcher.Removed += DeviceWatcher_Removed; // EnumerationCompleted and Stopped are optional to implement. //deviceWatcher.EnumerationCompleted += DeviceWatcher_EnumerationCompleted; //deviceWatcher.Stopped += DeviceWatcher_Stopped; //deviceWatcher.Received += DeviceWatcher_Received; // Start the watcher. deviceWatcher.Start(); }
private void StartScanDevice() { DeviceWatcher watcher = DeviceInformation.CreateWatcher(BluetoothLEDevice.GetDeviceSelectorFromPairingState(false)); watcher.Added += async(watcher2, deviceInfo) => { Debug.WriteLine(deviceInfo.Id + "," + deviceInfo.Name); if ((deviceInfo.Name != null && deviceInfo.Name.Trim() == "LG Lighting") || (deviceInfo.Id == (string)localSettings.Values["DeviceId"])) { if (this.device == null) { await ConnectAsync(deviceInfo); } } }; watcher.Removed += (watcher2, update) => { if (this.device != null && this.device.DeviceId == update.Id) { this.device = null; } }; watcher.Updated += (watcher2, update) => { }; watcher.Start(); }
private void StartWatcher() { UpdateConnected(false, SettingsHandler.DEVICE_CONNECT); string[] requestedProperties = { "System.Devices.Aep.DeviceAddress", "System.Devices.Aep.IsConnected", "System.Devices.Aep.Bluetooth.Le.IsConnectable" }; //TODO wwhere does this fit in? I seen it on a microsoft video but they didnt say.... string aqsAllBlueToothLEDevices = "{System.Devices.Aep.ProtocolId:=\"{bb7bb05e-5972-42b5-94fc-76eaa7084d49}\")"; deviceWatcher = DeviceInformation.CreateWatcher( BluetoothLEDevice.GetDeviceSelectorFromPairingState(false), requestedProperties, DeviceInformationKind.AssociationEndpoint); // Register event handlers before starting the watcher. // Added, Updated and Removed are required to get all nearby devices deviceWatcher.Added += DeviceWatcher_Added;; deviceWatcher.Updated += DeviceWatcher_Updated; deviceWatcher.Removed += DeviceWatcher_Removed; // EnumerationCompleted and Stopped are optional to implement. deviceWatcher.EnumerationCompleted += DeviceWatcher_EnumerationCompleted; deviceWatcher.Stopped += DeviceWatcher_Stopped; deviceWatcher.Start(); }
//////////////////////////////////////////////////////////////////////////////////////////// public void WatchDevices() { // from https://docs.microsoft.com/en-us/windows/uwp/devices-sensors/gatt-client // Query for extra properties you want returned string[] requestedProperties = { "System.Devices.Aep.DeviceAddress", "System.Devices.Aep.IsConnected" }; DeviceWatcher deviceWatcher = DeviceInformation.CreateWatcher( BluetoothLEDevice.GetDeviceSelectorFromPairingState(false), requestedProperties, DeviceInformationKind.AssociationEndpoint); // Register event handlers before starting the watcher. // Added, Updated and Removed are required to get all nearby devices deviceWatcher.Added += DeviceWatcher_Added; deviceWatcher.Updated += DeviceWatcher_Updated; deviceWatcher.Removed += DeviceWatcher_Removed; // EnumerationCompleted and Stopped are optional to implement. deviceWatcher.EnumerationCompleted += DeviceWatcher_EnumerationCompleted; deviceWatcher.Stopped += DeviceWatcher_Stopped; // Start the watcher. deviceWatcher.Start(); }
/// <returns>BluetoothAddress if a paired Muse bluetooth device is found</returns> public static Task <ulong?> FindPairedMuseDevice() { string query = BluetoothLEDevice.GetDeviceSelectorFromPairingState(true); var devWatch = DeviceInformation.CreateWatcher(query); var tcs = new TaskCompletionSource <ulong?>(); devWatch.Added += async(DeviceWatcher sender, DeviceInformation args) => { if (args.Name.IndexOf("Muse") < 0) { return; } devWatch.Stop(); // Stop immediately, otherwise EnumerationCompleted is triggered var device = await BluetoothLEDevice.FromIdAsync(args.Id); tcs.TrySetResult(device.BluetoothAddress); }; devWatch.EnumerationCompleted += (DeviceWatcher sender, object args) => { tcs.TrySetResult(null); devWatch.Stop(); }; devWatch.Start(); return(tcs.Task); }
public MainPage() { this.DataContext = new MainPageViewModel(); mqttService = new MqttService(); devicePicker = new DevicePicker(); this.devicePicker.DeviceSelected += async(devicePicker, args) => { var device = args.SelectedDevice; devicePicker.Hide(); await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { try { await mqttService.StartAsync(); await PairDeviceIfNecessary(device); await ConnectIGrill(device); Settings.SelectedDeviceId = device.Id; } catch (Exception ex) { } }); }; devicePicker.Filter.SupportedDeviceSelectors.Add(BluetoothLEDevice.GetDeviceSelectorFromPairingState(false)); devicePicker.Filter.SupportedDeviceSelectors.Add(BluetoothLEDevice.GetDeviceSelectorFromPairingState(true)); this.InitializeComponent(); }
public static AsqFilter NonPairedBluetoothDevicesFilter() { var bNonPaired = BluetoothDevice.GetDeviceSelectorFromPairingState(false); var bleNonPaired = BluetoothLEDevice.GetDeviceSelectorFromPairingState(false); return(new AsqFilter($"({bNonPaired}) OR ({bleNonPaired})")); }
public void StartScan(Action <BLE_Device_Info> execute) { DevicePicker picker = new DevicePicker(); picker.Filter.SupportedDeviceSelectors.Add(BluetoothLEDevice.GetDeviceSelectorFromPairingState(false)); picker.Filter.SupportedDeviceSelectors.Add(BluetoothLEDevice.GetDeviceSelectorFromPairingState(true)); picker.Show(new Rect()); }
public void TestFindAll() { var devices = DeviceInformation.FindAllAsync( $"{BluetoothLEDevice.GetDeviceSelectorFromPairingState(true)} OR " + $"{BluetoothLEDevice.GetDeviceSelectorFromPairingState(false)}").AsTask().GetAwaiter().GetResult(); foreach (var device in devices) { Debug.WriteLine(device.Name); } }
static async Task <IReadOnlyCollection <BluetoothDevice> > PlatformGetPairedDevices() { List <BluetoothDevice> devices = new List <BluetoothDevice>(); foreach (var device in await DeviceInformation.FindAllAsync(BluetoothLEDevice.GetDeviceSelectorFromPairingState(true))) { devices.Add(await BluetoothLEDevice.FromIdAsync(device.Id)); } return(devices.AsReadOnly()); }
private static async Task <DeviceInformation> GetDeviceInformation(bool paired) { var deviceSelector = BluetoothLEDevice.GetDeviceSelectorFromPairingState(paired); // Get a list of all devices var deviceInfoCollection = await DeviceInformation.FindAllAsync(deviceSelector); // See if the devices found are a Nuimo and return that if not return null var deviceInfo = deviceInfoCollection.FirstOrDefault(di => di.Name.Equals("Nuimo", StringComparison.CurrentCultureIgnoreCase)); return(deviceInfo); }
private void startWatcher() { deviceWatcher = DeviceInformation.CreateWatcher( BluetoothLEDevice.GetDeviceSelectorFromPairingState(true), requestedProperties, DeviceInformationKind.AssociationEndpoint); deviceWatcher.Added += DeviceWatcher_Added; deviceWatcher.Updated -= DeviceWatcher_Updated; deviceWatcher.Removed += DeviceWatcher_Removed; deviceWatcher.Start(); }
/// <summary> /// //////////////////////////////////////////// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void startWatcherButton_Click(object sender, RoutedEventArgs e) { startWatcherButton.IsEnabled = false; DevicePicker picker = new DevicePicker(); picker.Filter.SupportedDeviceSelectors.Add(BluetoothLEDevice.GetDeviceSelectorFromPairingState(false)); //picker.Filter.SupportedDeviceSelectors.Add(BluetoothLEDevice.GetDeviceSelectorFromPairingState(true)); picker.Show(new Rect(0, 0, 300, 400)); stopWatcherButton.IsEnabled = true; }
private void Button_Click(object sender, RoutedEventArgs e) { string[] requestedProperties = { "System.Devices.Aep.DeviceAddress", "System.Devices.Aep.IsConnected" }; DeviceWatcher deviceWatcher = DeviceInformation.CreateWatcher( BluetoothLEDevice.GetDeviceSelectorFromPairingState(false), requestedProperties, DeviceInformationKind.AssociationEndpoint); // Register event handlers before starting the watcher. // Added, Updated and Removed are required to get all nearby devices deviceWatcher.Added += new TypedEventHandler <DeviceWatcher, DeviceInformation>(async(watcher, devInfo) => { if (devInfo.Name != "") { await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { DeviceList.Text += String.Format("{0} : {1}\r\n", devInfo.Name, devInfo.Id); }); Console.WriteLine(String.Format("{0} : {1}", devInfo.Name, devInfo.Id)); } if (devInfo.Name == "MI Band 2") { Console.WriteLine("Find Mi"); BluetoothLEDevice bluetoothLeDevice = await BluetoothLEDevice.FromIdAsync(devInfo.Id); //Console.WriteLine(String.Format("{0} : {1}", bluetoothLeDevice.Name, bluetoothLeDevice.DeviceInformation)); } });; deviceWatcher.Updated += new TypedEventHandler <DeviceWatcher, DeviceInformationUpdate>(async(watcher, devInfo) => { });; deviceWatcher.Removed += new TypedEventHandler <DeviceWatcher, DeviceInformationUpdate>(async(watcher, devInfo) => { });; // EnumerationCompleted and Stopped are optional to implement. deviceWatcher.EnumerationCompleted += new TypedEventHandler <DeviceWatcher, Object>(async(watcher, obj) => { Console.WriteLine(String.Format("EnumerationCompleted")); }); deviceWatcher.Stopped += new TypedEventHandler <DeviceWatcher, Object>(async(watcher, obj) => { Console.WriteLine(String.Format("deviceWatcher.Stopped")); });; // Start the watcher. deviceWatcher.Start(); }
public void SearchSensor() { deviceWatcher = DeviceInformation.CreateWatcher( BluetoothLEDevice.GetDeviceSelectorFromPairingState(false), requestedProperties, DeviceInformationKind.AssociationEndpoint); deviceWatcher.Added += DeviceWatcher_Added; deviceWatcher.Updated -= DeviceWatcher_Updated; deviceWatcher.Removed += DeviceWatcher_Removed; deviceWatcher.EnumerationCompleted += DeviceWatcher_EnumerationCompleted; deviceWatcher.Start(); }
private string GetSelector(Schema.DeviceSelector deviceSelector) { switch (deviceSelector) { case Schema.DeviceSelector.BluetoothLePairedOnly: return(BluetoothLEDevice.GetDeviceSelectorFromPairingState(true)); case Schema.DeviceSelector.BluetoothLeUnpairedOnly: return(BluetoothLEDevice.GetDeviceSelectorFromPairingState(false)); default: return("(System.Devices.Aep.ProtocolId:=\"{bb7bb05e-5972-42b5-94fc-76eaa7084d49}\")"); } }
public static IAsyncOperation <DeviceInformation> PickSingleDeviceAsync() { if (!(Window.Current.Content is Frame rootFrame)) { throw new ArgumentException(nameof(rootFrame)); } var devicePicker = new DevicePicker(); devicePicker.Filter.SupportedDeviceSelectors.Add(BluetoothLEDevice.GetDeviceSelectorFromPairingState(false)); devicePicker.Filter.SupportedDeviceSelectors.Add(BluetoothLEDevice.GetDeviceSelectorFromPairingState(true)); return(devicePicker.PickSingleDeviceAsync(rootFrame.GetPickerRect())); }
public void StartScan(BleDevice device) { // Query for extra properties you want returned string[] requestedProperties = { "System.Devices.Aep.DeviceAddress", "System.Devices.Aep.IsConnected" }; _Watcher = DeviceInformation.CreateWatcher(BluetoothLEDevice.GetDeviceSelectorFromPairingState(false), requestedProperties, DeviceInformationKind.AssociationEndpoint); // register event handlers before starting the watcher. _Watcher.Added += DeviceWatcher_Added; _Watcher.Updated += DeviceWatcher_Updated; _Watcher.Removed += DeviceWatcher_Removed; _Watcher.Stopped += DeviceWatcher_Stopped; // Start the watcher. _Watcher.Start(); }
public void QueryDevices() { // Query for extra properties you want returned string[] requestedProperties = { "System.Devices.Aep.DeviceAddress", "System.Devices.Aep.IsConnected" }; deviceWatcher = DeviceInformation.CreateWatcher( BluetoothLEDevice.GetDeviceSelectorFromPairingState(false), requestedProperties, DeviceInformationKind.AssociationEndpoint); // Register event handlers before starting the watcher. // Added, Updated and Removed are required to get all nearby devices deviceWatcher.Added += DeviceWatcher_Added; deviceWatcher.Updated += DeviceWatcher_Updated; // Start the watcher. deviceWatcher.Start(); }
public RXBluetoothLEScanner(BluetoothManager bluetoothManager) { BluetoothManager = bluetoothManager; // Query for extra properties you want returned string[] requestedProperties = { "System.Devices.Aep.DeviceAddress", "System.Devices.Aep.IsConnected" }; BleDeviceWatcher = DeviceInformation.CreateWatcher( BluetoothLEDevice.GetDeviceSelectorFromPairingState(false), requestedProperties, DeviceInformationKind.AssociationEndpoint); BleDeviceWatcher.Added += BleDeviceWatcher_Added; BleDeviceWatcher.EnumerationCompleted += BleDeviceWatcher_EnumerationCompleted; BleDeviceWatcher.Removed += BleDeviceWatcher_Removed; BleDeviceWatcher.Stopped += BleDeviceWatcher_Stopped; BleDeviceWatcher.Updated += BleDeviceWatcher_Updated; }
/// <summary> /// Constructor /// </summary> public BleDeviceWatcher() { mDeviceWatcher = DeviceInformation.CreateWatcher( BluetoothLEDevice.GetDeviceSelectorFromPairingState(false), mRequestedProperties, DeviceInformationKind.AssociationEndpoint); mDeviceWatcher.Added += Added; mDeviceWatcher.Updated += Updated; mDeviceWatcher.Removed += Removed; mDeviceWatcher.EnumerationCompleted += (sender, args) => { EnumCompleted(); mDeviceWatcher.Stop(); }; mDeviceWatcher.Stopped += (sender, args) => { Stopped(); }; }
public ClientBLE() { //Get all devices paired and not. string query1 = "(" + BluetoothLEDevice.GetDeviceSelectorFromPairingState(true) + ")"; string query2 = "(" + BluetoothLEDevice.GetDeviceSelectorFromPairingState(false) + ")"; var query = query1 + " OR " + query2; //Create device watcher mDeviceWatcher = DeviceInformation.CreateWatcher(query, new string[] { "System.Devices.Aep.DeviceAddress", "System.Devices.Aep.IsConnected" }, DeviceInformationKind.AssociationEndpoint); // Register event handlers before starting the watcher. // Added, Updated and Removed are required to get all nearby devices mDeviceWatcher.Added += DeviceWatcher_Added; mDeviceWatcher.Updated += DeviceWatcher_Updated; // Start the watcher. Start(); }
/// <summary> /// Discovery BLE devices in range /// </summary> private void discovery() { Console.WriteLine("Discovering devices..."); // Query for extra properties you want returned string[] requestedProperties = { "System.Devices.Aep.DeviceAddress", "System.Devices.Aep.IsConnected" }; DeviceWatcher deviceWatcher = DeviceInformation.CreateWatcher( BluetoothLEDevice.GetDeviceSelectorFromPairingState(false), requestedProperties, DeviceInformationKind.AssociationEndpoint); deviceWatcher.Added += DeviceWatcher_Added; // Start the watcher. deviceWatcher.Start(); Console.ReadLine(); }
async Task <BluetoothDevice> DoRequestDevice(RequestDeviceOptions options) { DevicePicker picker = new DevicePicker(); picker.Appearance.AccentColor = Windows.UI.Color.FromArgb(0xff, 0xff, 0xff, 0xff); picker.Appearance.ForegroundColor = Windows.UI.Color.FromArgb(0xff, 0xff, 0xff, 0xff); picker.Appearance.Title = Windows.ApplicationModel.Package.Current.DisplayName + " wants to pair"; if (!options.AcceptAllDevices) { foreach (var filter in options.Filters) { if (!string.IsNullOrEmpty(filter.Name)) { picker.Filter.SupportedDeviceSelectors.Add(BluetoothLEDevice.GetDeviceSelectorFromDeviceName(filter.Name)); } foreach (var service in filter.Services) { picker.Filter.SupportedDeviceSelectors.Add(GattDeviceService.GetDeviceSelectorFromUuid(service)); } } } if (picker.Filter.SupportedDeviceSelectors.Count == 0) { //picker.Filter.SupportedDeviceSelectors.Add(BluetoothLEDevice.GetDeviceSelector()); picker.Filter.SupportedDeviceSelectors.Add(BluetoothLEDevice.GetDeviceSelectorFromPairingState(true)); picker.Filter.SupportedDeviceSelectors.Add(BluetoothLEDevice.GetDeviceSelectorFromPairingState(false)); } var deviceInfo = await picker.PickSingleDeviceAsync(Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().VisibleBounds); if (deviceInfo == null) { return(null); } var device = await BluetoothLEDevice.FromIdAsync(deviceInfo.Id); return(new BluetoothDevice(device)); }
private async void ShowDevicePicker() { devicePicker = new DevicePicker(); // only show Bluetooth Low Energy devices devicePicker.Filter.SupportedDeviceSelectors.Add(BluetoothLEDevice.GetDeviceSelectorFromPairingState(true)); devicePicker.Filter.SupportedDeviceSelectors.Add(BluetoothLEDevice.GetDeviceSelectorFromPairingState(false)); // Calculate the position to show the picker (right below the buttons) GeneralTransform ge = pickDeviceButton.TransformToVisual(null); Point point = ge.TransformPoint(new Point()); Rect rect = new Rect(point, new Point(point.X + pickDeviceButton.ActualWidth, point.Y + pickDeviceButton.ActualHeight)); DeviceInformation di = await devicePicker.PickSingleDeviceAsync(rect); if (null != di) { ViewModel.GearVrController = new GearVrController(); await ViewModel.GearVrController.Create(di); } }
public void StartScanningForMyo() { if (!_scanningForMyo) { _scanningForMyo = true; _bleAdWatcher = new BluetoothLEAdvertisementWatcher { ScanningMode = BluetoothLEScanningMode.Active }; _bleAdWatcher.Received += OnBleAdvertisementReceived; _bleAdWatcher.AdvertisementFilter.Advertisement.ServiceUuids.Clear(); _bleAdWatcher.AdvertisementFilter.Advertisement.ServiceUuids.Add(ControlServiceUUID); _bleAdWatcher.Start(); string[] requestedProperties = { "System.Devices.Aep.DeviceAddress", "System.Devices.Aep.IsConnected" }; _bleDeviceWatcher = DeviceInformation.CreateWatcher(BluetoothLEDevice.GetDeviceSelectorFromPairingState(true), requestedProperties, DeviceInformationKind.AssociationEndpoint); _bleDeviceWatcher.Added += OnDeviceAdded; _bleDeviceWatcher.Updated += OnDeviceUpdated; _bleDeviceWatcher.Removed += OnDeviceRemoved; _bleDeviceWatcher.Start(); } }
/// <summary> /// Call Start method to detect device and activate notification flow. /// </summary> public void Start() { deviceWatcher = DeviceInformation.CreateWatcher( BluetoothLEDevice.GetDeviceSelectorFromPairingState(paired), requestedProperties, DeviceInformationKind.AssociationEndpoint); // Register event handlers before starting the watcher. // Added, Updated and Removed are required to get all nearby devices deviceWatcher.Added += DeviceWatcher_Added; deviceWatcher.Updated += DeviceWatcher_Updated; deviceWatcher.Removed += DeviceWatcher_Removed; // EnumerationCompleted and Stopped are optional to implement. deviceWatcher.EnumerationCompleted += DeviceWatcher_EnumerationCompleted; deviceWatcher.Stopped += DeviceWatcher_Stopped; // Start the watcher. deviceWatcher.Start(); }
private async void FindKeyboard() { string deviceSelectorInfo = BluetoothLEDevice.GetDeviceSelectorFromPairingState(true); DeviceInformationCollection deviceInfoCollection = await DeviceInformation.FindAllAsync(deviceSelectorInfo, null); foreach (DeviceInformation device_info in deviceInfoCollection) { // Do not let the background task starve, check if we are paired then connect to the keyboard if (device_info.Name.Contains("ANNE") && device_info.Pairing.IsPaired) { ConnectToKeyboard(device_info); break; } } // if the device was never paired start doing the background check // Make sure to disable Bluetooth listener this.SetupBluetooth(); }
private async void ClickedMethod(object obj) { var devicePicker = new DevicePicker(); devicePicker.Filter.SupportedDeviceSelectors.Add(BluetoothLEDevice.GetDeviceSelectorFromPairingState(true)); // Calculate the position to show the picker (right below the buttons) Button DiscoverButton = obj as Button; if (DiscoverButton != null) { var ge = DiscoverButton.TransformToVisual(null); var point = ge.TransformPoint(new Point()); var rect = new Rect(point, new Point(100, 100)); var device = await devicePicker.PickSingleDeviceAsync(rect); if (device != null) { var bluetoothLEDevice = await BluetoothLEDevice.FromIdAsync(device.Id); } } }