public void Defaults() { var options = new PeripheralScanningOptions(); Assert.That(options.Dictionary.Count, Is.EqualTo(0), "Count"); Assert.False(options.AllowDuplicatesKey, "AllowDuplicatesKey"); }
public BtError enumerateDevices() { if (!isScanning) { devices.Clear(); deviceAddresses.Clear(); serviceObjects.Clear(); characteristicObjects.Clear(); descriptorObjects.Clear(); var error = checkBtSupport(); if (error != BtError.None) { return(error); } var uuids = new List <CBUUID>(); foreach (var s in scanServices) { uuids.Add(CBUUID.FromString(s)); } var options = new PeripheralScanningOptions(); options.AllowDuplicatesKey = true; centralManager.ScanForPeripherals(uuids.ToArray(), options); isScanning = true; return(BtError.None); } else { return(BtError.AlreadyRunning); } }
public void AllowDuplicatesKey_True() { var options = new PeripheralScanningOptions() { AllowDuplicatesKey = true }; Assert.That(options.Dictionary.Count, Is.EqualTo(1), "Count"); Assert.True(options.AllowDuplicatesKey, "AllowDuplicatesKey"); }
static void OnManagerUpdatedState(object sender, EventArgs e) { if ((int)manager.State == (int)CBManagerState.PoweredOn) { PeripheralScanningOptions opts = new PeripheralScanningOptions(); opts.AllowDuplicatesKey = true; manager.ScanForPeripherals(peripheralUuids: null, options: opts.Dictionary); } }
public void AllowDuplicatesKey_False() { var options = new PeripheralScanningOptions() { AllowDuplicatesKey = false }; Assert.That(options.Dictionary.Count, Is.EqualTo((nuint)1), "Count"); Assert.False(options.AllowDuplicatesKey, "AllowDuplicatesKey"); }
public void StartScan() { Console.WriteLine("Start Ibeacon "); if (CBCentralManagerState.PoweredOn == this._manager.State) { var uuids = new CBUUID[0]; PeripheralScanningOptions options = new PeripheralScanningOptions(); options.AllowDuplicatesKey = true; this._manager.ScanForPeripherals(uuids, options); } }
/// <summary> /// Start scanning for devices. /// </summary> /// <param name="serviceUuids">White-listed service UUIDs</param> public async void StartScanningForDevices(params string[] serviceUuids) { if (IsScanning) { return; } if (_centralManager.State != CBCentralManagerState.PoweredOn) { throw new InvalidStateException((ManagerState)_centralManager.State); } Debug.WriteLine("StartScanningForDevices"); var uuids = new List <CBUUID>(); foreach (var guid in serviceUuids) { uuids.Add(CBUUID.FromString(guid)); } IsScanning = true; var options = new PeripheralScanningOptions() { }; _discoveringDevices = new List <IDevice>(); _centralManager.ScanForPeripherals(uuids.ToArray(), options); // Wait for the timeout _scanCancellationToken = new CancellationTokenSource(); try { await Task.Delay(ScanTimeout, _scanCancellationToken.Token); _scanCancellationToken = null; } catch (Exception) { // ignored } if (IsScanning) { StopScanningForDevices(); var currentDevices = _devices.Select(x => x.Id); var newDevices = _discoveringDevices.Select(x => x.Id); var removeList = currentDevices.Except(newDevices); _devices.RemoveAll(x => removeList.Any(g => g == x.Id)); ScanTimeoutElapsed(this, new DevicesDiscoveredEventArgs(_discoveringDevices)); } }
// This method scans for Bluetooth devices public async Task Scan(int scanInterval) { // empty array to scan for everything CBUUID[] cbuuids = null; PeripheralScanningOptions scanningOptions = new PeripheralScanningOptions(); scanningOptions.AllowDuplicatesKey = false; this.manager.ScanForPeripherals(cbuuids, scanningOptions); Console.WriteLine("Scanning started"); // Stop scanning after specified amount of time await Task.Delay(scanInterval); this.StopScan(); }
public async Task <List <string> > scanDevices() { //throw new NotImplementedException(); //ea.ShowBluetoothAccessoryPicker(null, null); Console.WriteLine("Start scan request!"); var u = CBUUID.FromString("00001101-0000-1000-8000-00805f9b34fb"); var a = new CBUUID[] { u }; if (!bluetoothManager.IsScanning) { //bluetoothManager.StopScan(); bluetoothManager.RetrievePeripherals(a); PeripheralScanningOptions option = new PeripheralScanningOptions(NSDictionary.FromObjectAndKey(CBCentralManager.ScanOptionSolicitedServiceUUIDsKey, CBUUID.FromString("00001101-0000-1000-8000-00805F9B34FB"))); bluetoothManager.ScanForPeripherals(a, option); } await Task.Delay(8000); /** bluetoothManager.ScanForPeripherals(null, option); * List<string> devices = new List<string>(); * bluetoothManager.RetrievePeripherals(CBUUID.FromString("00001101-0000-1000-8000-00805F9B34FB")); * * * bluetoothManager.DiscoveredPeripheral += (sender, e) => * { * * var name = e.Peripheral.UUID; * string uuid = name.ToString(); * devices.Add(uuid); * if (e.AdvertisementData.ContainsKey(CBAdvertisement.DataLocalNameKey)) * { * // iOS caches the peripheral name, so it can become stale (if changing) * // keep track of the local name key manually * name = ((NSString)e.AdvertisementData.ValueForKey(CBAdvertisement.)).ToString(); * * } * };**/ List <string> ids = new List <string>(); /**foreach (CBUUID uuid in a) * { * ids.Add(uuid.ToString()); * }***/ foreach (CBPeripheral p in retrievedDevices) { ids.Add(p.UUID.ToString()); } return(ids); }
public void Start() { PeripheralScanningOptions scanningOptions = new PeripheralScanningOptions(); switch (this.DriverState) { case BluetoothDriverStates.Enabled: try { this.centralManager.ScanForPeripherals(this.scanFilter, scanningOptions); } catch (Exception exc) { System.Diagnostics.Debug.WriteLine(exc.ToString()); } this.DriverState = BluetoothDriverStates.Discovering; break; } }
// Implemented for IConnectionManager public bool StartScan() { lock (centralManager) { if (isScanning) { return(true); } try { var options = new PeripheralScanningOptions(); options.AllowDuplicatesKey = true; centralManager.ScanForPeripherals(default(CBUUID[]), options); isScanning = true; return(true); } catch (Exception e) { Log.E(this, "Failed to start ios scan", e); isScanning = false; return(false); } } }
public void StartContinuosScan() { if (IsScanning) { return; } if (_centralManager.State != CBCentralManagerState.PoweredOn) { throw new InvalidStateException((ManagerState)_centralManager.State); } IsScanning = true; _discoveringDevices = new List <IDevice>(); var uuids = new List <CBUUID>(); var options = new PeripheralScanningOptions() { }; _centralManager.ScanForPeripherals(uuids.ToArray(), options); }
public void Start(TracingInformation config) { if (config == null || _enabled == true) { return; } _tracingInformation = config; CBUUID uuidService = CBUUID.FromString(_tracingInformation.ServiceId); CBUUID uuidCharacteristic = CBUUID.FromString(_tracingInformation.CharacteristicId); // TODO: options prevent android from being discovered on IOS, investigation required var options = new PeripheralScanningOptions() { AllowDuplicatesKey = true }; _centralManager.ScanForPeripherals(new CBUUID[] { uuidService }, options); _enabled = true; Covi.Features.BluetoothTracing.TracingState.Instance.SetScanningState(true); _logger.LogDebug($"Scanning started for service {_tracingInformation.ServiceId}."); }