示例#1
0
 static void OnPeripheralDiscoveredCharacteristic(object sender, CBServiceEventArgs e)
 {
     foreach (CBCharacteristic c in e.Service.Characteristics)
     {
         Console.WriteLine("Discovered characteristic {0}", c);
     }
 }
示例#2
0
        void NativeDeviceDiscoveredCharacteristic(object sender, CBServiceEventArgs e)
        {
            Console.WriteLine("Device.Discovered Characteristics.");
            //loop through each service, and update the characteristics
            foreach (CBService srv in ((CBPeripheral)sender).Services)
            {
                // if the service has characteristics yet
                if (srv.Characteristics != null)
                {
                    // locate the our new service
                    foreach (var item in this.Services)
                    {
                        // if we found the service
                        if (item.ID == Service.ServiceUuidToGuid(srv.UUID))
                        {
                            item.Characteristics.Clear();

                            // add the discovered characteristics to the particular service
                            foreach (var characteristic in srv.Characteristics)
                            {
                                Console.WriteLine("Characteristic: " + characteristic.Description);
                                Characteristic newChar = new Characteristic(characteristic, this.nativeDevice);
                                item.Characteristics.Add(newChar);
                            }

                            // inform the service that the characteristics have been discovered
                            // TODO: really, we should just be using a notifying collection.
                            (item as Service).OnCharacteristicsDiscovered();
                        }
                    }
                }
            }
        }
示例#3
0
        void OnDiscoveredCharacteristic(object sender, CBServiceEventArgs e)
        {
            BLEService service = null;

            foreach (BLEService bles in services)
            {
                if (bles.UUID.StringValue == e.Service.UUID.ToString(true))
                {
                    service = bles;

                    break;
                }
            }

            foreach (CBCharacteristic cbc in e.Service.Characteristics)
            {
                BLECharacteristic blec = new BLECharacteristic(cbc);

                service.Characteristics.Add(blec);
            }

            EventHandler <BLEServiceEventArgs> handler = DiscoveredCharacteristic;

            if (handler != null)
            {
                BLEServiceEventArgs args = new BLEServiceEventArgs();
                args.Service = service;
                args.Error   = e.Error?.ToString();

                handler(this, args);
            }
        }
 private void _peripheral_DiscoveredCharacteristic(object sender, CBServiceEventArgs e)
 {
     if (e.Service == _service)
     {
         Debug.WriteLine(DateTimeOffset.Now.ToString() + " DiscoveredCharacteristic");
     }
 }
示例#5
0
        void Peripheral_DiscoveredCharacteristic(object sender, CBServiceEventArgs e)
        {
            var peripheral     = (CBPeripheral)sender;
            var ble_peripheral = devices [peripheral.Identifier.ToString()];

            ble_peripheral.Characteristics.Add(new BleCharacteristic()
            {
                Name = "?"
            });

            OnSomethingHappened();
        }
示例#6
0
        void DiscoveredCharacteristicsForService(object sender, CBServiceEventArgs e)
        {
            if (e.Error != null)
            {
                Console.Error.WriteLine($"Could not discover characteristics: {e.Error.Description}");
                Environment.Exit(1);
            }

            connectedCbPeripheral.DiscoveredCharacteristic -= DiscoveredCharacteristicsForService;
            var service         = e.Service;
            var characteristics = Array.ConvertAll(service.Characteristics, c => new Characteristic(c.UUID.Uuid));

            DiscoveredCharacteristicsEventHandler?.Invoke(this, new DiscoveredCharacteristicsEventArgs(new Service(service.UUID.Uuid), characteristics));
        }
示例#7
0
		private void DiscoveredCharacteristic(object sender, CBServiceEventArgs args)
		{
			if (args.Service.UUID != _nativeService.UUID)
				return;
			
			foreach (var c in args.Service.Characteristics)
			{
				var charId = c.UUID.ToString().ToGuid();
				if (Characteristics.All(x => x.Id != charId))
				{
					var characteristic = new Characteristic(_peripheral, c);
					Characteristics.Add(characteristic);

					CharacteristicDiscovered(this, new CharacteristicDiscoveredEventArgs(characteristic));
				}
			}
		}
示例#8
0
        private void DiscoveredCharacteristic(object sender, CBServiceEventArgs args)
        {
            if (args.Service.UUID != NativeService.UUID)
            {
                return;
            }

            Characteristics.Clear();
            foreach (var c in args.Service.Characteristics)
            {
                var charId = c.UUID.ToString().ToGuid();
                if (Characteristics.All(x => x.Id != charId))
                {
                    var characteristic = new Characteristic(_peripheral, c);
                    Characteristics.Add(characteristic);
                }
            }
            CharacteristicDiscovered(this, new CharacteristicsDiscoveredEventArgs(Characteristics));
        }
示例#9
0
        private void OnDiscoveredCharacteristic(object sender, CBServiceEventArgs e)
        {
            if (!ReferenceEquals(e.Service, _service))
            {
                return;
            }

            if (e.Error != null)
            {
                RaiseDiscoverCharacteristicsFailed(e.Error.ToShared());
            }
            else
            {
                var characteristics = _service
                                      .Characteristics
                                      .Select(c => new BLECharacteristic(PeripheralWrapper, c))
                                      .ToList();
                RaiseCharacteristicsDiscovered(characteristics);
            }
        }
示例#10
0
        private void DiscoveredCharacteristic(object sender, CBServiceEventArgs args)
        {
            var characteristics = args.Service.Characteristics;

            try
            {
                MessageCharacteristic = characteristics.First(ch => ch.IsUuidEqual(BluetoothServiceUuid.MessageCharacteristic));
                InvitationCharacteristic = characteristics.First(ch => ch.UUID == BluetoothServiceUuid.ConnectionInviteCharacteristic);
                StatusCharacteristic = characteristics.First(ch => ch.UUID == BluetoothServiceUuid.StatusCharacteristic);
                NameCharacteristic = characteristics.First(ch => ch.UUID == BluetoothServiceUuid.NameCharacteristic);

                //Subscribe notify characteristic to receive messages from another user
                _peripheral.SetNotifyValue(true, StatusCharacteristic);
                _peripheral.SetNotifyValue(true, NameCharacteristic);
            }
            catch (Exception ex)
            {
                _discoveryTaskSource.TrySetException(new Exception("Bluetooth: Failed to discover characteristics", ex));
            }
        }
示例#11
0
 private void OnDiscoveredCharacteristic(object sender, CBServiceEventArgs e)
 => _wes.RaiseEvent(nameof(DiscoveredCharacteristic), sender, e);
示例#12
0
 private void OnDiscoveredIncludedService(object sender, CBServiceEventArgs e)
 => _wes.RaiseEvent(nameof(DiscoveredIncludedService), sender, e);
示例#13
0
 void nativeDevice_DiscoveredCharacteristic(object sender, CBServiceEventArgs e)
 {
     _characteristicsDiscovered.Set();
 }