Пример #1
0
		public static void ScanForHeartRateMonitors (CBCentralManager manager)
		{
			if (manager == null) {
				throw new ArgumentNullException ("manager");
			}

			manager.ScanForPeripherals (PeripheralUUID);			
		}
Пример #2
0
        public IEnumerable <BluetoothDevice> ScanForDevices()
        {
            _devices       = new List <BluetoothDevice>();
            _nativeDevices = new List <CBPeripheral>();
            _manager?.ScanForPeripherals(CBUUID.FromString("00001101-0000-1000-8000-00805F9B34FB"));
            _manager?.StopScan();

            return(_devices);
        }
        public void ScanForBroadcasters(CBCentralManager mgr, UIButton Scanner)
        {
            //Passing in null scans for all peripherals. Peripherals can be targeted by using CBUIIDs
            mgr.ScanForPeripherals (cbuuids); //Initiates async calls of DiscoveredPeripheral

            Scanner.SetTitle("Started scan Scan", UIControlState.Normal);
            //Timeout after 30 seconds
            var timer = new Timer (30 * 1000);

            //mgr.StopScan ();

            timer.Elapsed += (sender, e) => {
                Console.WriteLine("Stopping scan");
                mgr.StopScan ();
                Console.WriteLine("Scan stopped");
                Scanner.SetTitle("Stopped Scan", UIControlState.Normal);
            };
        }
Пример #4
0
        protected override async Task StartScanningForDevicesNativeAsync(Guid[] serviceUuids, bool allowDuplicatesKey, CancellationToken scanCancellationToken)
        {
            // Wait for the PoweredOn state
            await WaitForState(CBCentralManagerState.PoweredOn, scanCancellationToken).ConfigureAwait(false);

            if (scanCancellationToken.IsCancellationRequested)
            {
                throw new TaskCanceledException("StartScanningForDevicesNativeAsync cancelled");
            }

            Trace.Message("Adapter: Starting a scan for devices.");

            CBUUID[] serviceCbuuids = null;
            if (serviceUuids != null && serviceUuids.Any())
            {
                serviceCbuuids = serviceUuids.Select(u => CBUUID.FromString(u.ToString())).ToArray();
                Trace.Message("Adapter: Scanning for " + serviceCbuuids.First());
            }

            _centralManager.ScanForPeripherals(serviceCbuuids, new PeripheralScanningOptions {
                AllowDuplicatesKey = allowDuplicatesKey
            });
        }
Пример #5
0
        public Task StartScanningForDevicesAsync(ScanMode mode, Guid[] serviceUuids = null, bool allowDuplicatesKey = false, CancellationToken cancellationToken = default)
        {
            if (centralManager.State == CBCentralManagerState.PoweredOn)
            {
                Console.WriteLine("BluetoothCentralService: Starting a scan for devices.");

                CBUUID[] serviceCbuuids = null;
                if (serviceUuids != null && serviceUuids.Any())
                {
                    serviceCbuuids = serviceUuids.Select(uuid => uuid.cbuuidFromGuid()).ToArray();
                }

                centralManager.ScanForPeripherals(serviceCbuuids, new PeripheralScanningOptions {
                    AllowDuplicatesKey = allowDuplicatesKey
                });
                Console.WriteLine("BluetoothCentralService: Scanning for " + serviceCbuuids.First());
                return(Task.CompletedTask);
            }
            else
            {
                throw new TaskCanceledException("Scanning cancelled, Bluetooth is not ON");
            }
        }
Пример #6
0
        private void StartScanningSynchronized()
        {
            if (_centralManager.State != CBCentralManagerState.PoweredOn)
            {
                _shouldBeScanning = true;
                MvxTrace.TaggedTrace(MvxTraceLevel.Diagnostic, "Beacons", $"CentralManager state is {_centralManager.State}, cannot start scan");
            }
            else
            {
                MvxTrace.TaggedTrace(MvxTraceLevel.Diagnostic, "Beacons", "Starting to scan for Eddystones");

                var peripheralUuids = new List <CBUUID>();
                peripheralUuids.Add(CBUUID.FromString("FEAA")); //eddystone service id

                //peripheralUuids.Add(CBUUID.FromString("0215")); //ibeacon service id, but don't work
                //peripheralUuids.Add(CBUUID.FromBytes(new byte[] { 0x02, 0x15 }));

                //peripheralUuids.Add(CBUUID.FromBytes(new byte[] { 0x02, 0x01 }));
                //peripheralUuids.Add(CBUUID.FromBytes(new byte[] { 0x02, 0x01, 0x1a, 0x1a }));
                //peripheralUuids.Add(CBUUID.FromBytes(new byte[] { 0x1a, 0x1a }));
                //peripheralUuids.Add(CBUUID.FromBytes(new byte[] { 0x4c, 0x00 }));
                //peripheralUuids.Add(CBUUID.FromBytes(new byte[] { 0x4c, 0x00, 0x02, 0x15 }));

                // 02 01 1a 1a ff 4c 00 02 15 – #Apple's fixed iBeacon advertising prefix
                // стартовать поиск всех устройств BLE и отбирать среди них тех, у кого есть последовательность байт как в предыдущей строке

                //Полезные ссылки:
                //https://github.com/AltBeacon/android-beacon-library/blob/master/src/main/java/org/altbeacon/beacon/BeaconParser.java
                //https://glimwormbeacons.com/learn/what-makes-an-ibeacon-an-ibeacon/
                //http://stackoverflow.com/questions/20387327/using-corebluetooth-with-ibeacons

                _centralManager.ScanForPeripherals(
                    peripheralUuids.ToArray(),
                    new PeripheralScanningOptions(NSDictionary.FromObjectAndKey(NSObject.FromObject(true), CBCentralManager.ScanOptionAllowDuplicatesKey))
                    );
            }
        }
Пример #7
0
        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}.");
        }
Пример #8
0
        public override void UpdatedState(CBCentralManager central)
        {
            switch (central.State)
            {
            case CBCentralManagerState.Unknown:
                Debug.WriteLine("CBCentralManagerState.Unknown");
                break;

            case CBCentralManagerState.Resetting:
                Debug.WriteLine("CBCentralManagerState.Resetting");
                break;

            case CBCentralManagerState.Unsupported:
                Debug.WriteLine("CBCentralManagerState.Unsupported");
                break;

            case CBCentralManagerState.Unauthorized:
                Debug.WriteLine("CBCentralManagerState.Unauthorized");
                break;

            case CBCentralManagerState.PoweredOff:
                Debug.WriteLine("CBCentralManagerState.PoweredOff");
                break;

            case CBCentralManagerState.PoweredOn:
                Debug.WriteLine("CBCentralManagerState.PoweredOn");
                central.ScanForPeripherals(peripheralUuids: new CBUUID[] { },
                                           options: new PeripheralScanningOptions {
                    AllowDuplicatesKey = true
                });
                break;

            default:
                throw new NotImplementedException();
            }
        }
Пример #9
0
        /// <summary>
        /// Start scanning for devices.
        /// </summary>
        /// <param name="serviceUuids">White-listed service UUIDs</param>
        public async void StartScanningForDevices(params string[] serviceUuids)
        {
            await WaitForState(CBCentralManagerState.PoweredOn);

            var uuids = new List <CBUUID>();

            foreach (var guid in serviceUuids)
            {
                uuids.Add(CBUUID.FromString(guid));
            }

            DiscoveredDevices = new List <IDevice>();
            IsScanning        = true;

            _central.ScanForPeripherals(uuids.ToArray());

            await Task.Delay(ScanTimeout);

            if (IsScanning)
            {
                StopScanningForDevices();
                ScanTimeoutElapsed(this, EventArgs.Empty);
            }
        }
Пример #10
0
 public void ScanForPeripherals()
 {
     mgr.ScanForPeripherals((CBUUID[])null, (NSDictionary)null);
 }
Пример #11
0
 public void ScanForPeripherals()
 {
     nativeManager.ScanForPeripherals(peripheralUuids: null);
 }