Exemple #1
0
 void Peripheral_UpdatedCharacterteristicValue(object sender, CBCharacteristicEventArgs e)
 {
     if (e.Characteristic == _characteristic)
     {
         characteristicValueChanged?.Invoke(this, EventArgs.Empty);
     }
 }
Exemple #2
0
 void Peripheral_UpdatedCharacterteristicValue(object sender, CBCharacteristicEventArgs e)
 {
     if (e.Characteristic == _characteristic)
     {
         OnCharacteristicValueChanged(new GattCharacteristicValueChangedEventArgs(e.Characteristic.Value.ToArray()));
     }
 }
Exemple #3
0
        void OnUpdatedCharacteristicValue(object sender, CBCharacteristicEventArgs e)
        {
            BLECharacteristic characteristic = null;

            foreach (BLEService bles in services)
            {
                foreach (BLECharacteristic blec in bles.Characteristics)
                {
                    if (blec.UUID.StringValue.Equals(e.Characteristic.UUID.ToString()))
                    {
                        characteristic = blec;

                        break;
                    }
                }
            }

            characteristic.Value = e.Characteristic.Value.ToArray();

            EventHandler <BLECharacteristicEventArgs> handler = UpdatedCharacteristicValue;

            if (handler != null)
            {
                BLECharacteristicEventArgs args = new BLECharacteristicEventArgs();
                args.Characteristic = characteristic;
                args.Error          = e.Error?.ToString();

                handler(this, args);
            }
        }
 private void _peripheral_DiscoveredDescriptor(object sender, CBCharacteristicEventArgs e)
 {
     if (e.Characteristic == _characteristic)
     {
         Debug.WriteLine(DateTimeOffset.Now.ToString() + " DiscoveredDescriptor");
     }
 }
 private void UpdatedCharacteristicValue(object sender, CBCharacteristicEventArgs e)
 {
     if (e.Characteristic.UUID == _nativeCharacteristic.UUID)
     {
         ValueUpdated(this, new CharacteristicReadEventArgs(this));
     }
 }
		void HandleDiscoveredDescriptor (object sender, CBCharacteristicEventArgs e)
		{
			foreach (var descriptor in e.Characteristic.Descriptors)
				Console.WriteLine ("Characteristic: {0} Discovered Descriptor: {1}", e.Characteristic.Value, descriptor);

			CharacteristicsTable.ReloadData();
		}
Exemple #7
0
 // continues to listen indefinitely
 void UpdatedNotify(object sender, CBCharacteristicEventArgs e)
 {
     this.ValueUpdated(this, new CharacteristicReadEventArgs()
     {
         Characteristic = new Characteristic(e.Characteristic, _parentDevice)
     });
 }
 private void UpdatedNotify(Object sender, CBCharacteristicEventArgs e)
 {
     if (e.Characteristic.UUID == this._nativeCharacteristic.UUID)
     {
         this.ValueUpdated?.Invoke(this, new CharacteristicUpdatedEventArgs(this));
     }
 }
Exemple #9
0
 // removes listener after first response received
 void UpdatedRead(object sender, CBCharacteristicEventArgs e)
 {
     this.ValueUpdated(this, new CharacteristicReadEventArgs()
     {
         Characteristic = new Characteristic(e.Characteristic, _parentDevice)
     });
     _parentDevice.UpdatedCharacterteristicValue -= UpdatedRead;
 }
Exemple #10
0
        static void OnPeripheralUpdatedCharacteristicValue(object sender, CBCharacteristicEventArgs e)
        {
            if (e.Characteristic.Value == null)
            {
                return;
            }

            Notified?.Invoke(null, new NotificationEventArgs());
        }
        void HandleDiscoveredDescriptor(object sender, CBCharacteristicEventArgs e)
        {
            foreach (var descriptor in e.Characteristic.Descriptors)
            {
                Console.WriteLine("Characteristic: {0} Discovered Descriptor: {1}", e.Characteristic.Value, descriptor);
            }

            CharacteristicsTable.ReloadData();
        }
 // continues to listen indefinitely
 private void UpdatedNotify(object sender, CBCharacteristicEventArgs e)
 {
     if (e.Characteristic.UUID == _nativeCharacteristic.UUID)
     {
         ValueUpdated(this, new CharacteristicReadEventArgs
         {
             Characteristic = new Characteristic(e.Characteristic, _parentDevice)
         });
     }
 }
        private void OnCharacteristicWrite(object sender, CBCharacteristicEventArgs e)
        {
            if (e.Characteristic.UUID != _nativeCharacteristic.UUID)
            {
                return;
            }

            _parentDevice.WroteCharacteristicValue -= OnCharacteristicWrite;
            ValueWritten(this, new CharacteristicWriteEventArgs(this, e.Error == null));
        }
        private void OnWroteCharacteristicValue(object sender, CBCharacteristicEventArgs cbCharacteristicEventArgs)
        {
            var c   = cbCharacteristicEventArgs.Characteristic;
            var cId = c.UUID;
            var tId = _nativeCharacteristic.UUID;

            if (cId == tId)
            {
                WriteComplete?.Invoke(this, new CharacteristicWriteEventArgs(cbCharacteristicEventArgs.Error == null, this));
            }
        }
        void HandleUpdatedCharacterteristicValue(object sender, CBCharacteristicEventArgs e)
        {
            CBPeripheral peripheral = sender as CBPeripheral;
            if (peripheral == null || peripheral != Peripheral)
                return;

            if (e.Error == null)
                OnCharacteristicChanged(this, new BleCharacteristicChangedEventArgs(e.Characteristic, e.Characteristic.Value.ToArray(), BleGattOperationState.Success));
            else
                OnCharacteristicChanged(this, new BleCharacteristicChangedEventArgs(e.Characteristic, e.Characteristic.Value.ToArray(), BleGattOperationState.Failure));
        }
        private void OnUpdatedCharacteristicValue(object sender, CBCharacteristicEventArgs e)
        {
            var c   = e.Characteristic;
            var cId = c.UUID;
            var tId = _nativeCharacteristic.UUID;

            if (cId == tId)
            {
                ValueUpdated?.Invoke(this, new CharacteristicUpdateEventArgs(this));
            }
        }
        void HandleWroteCharacteristicValue(object sender, CBCharacteristicEventArgs e)
        {
            CBPeripheral peripheral = sender as CBPeripheral;
            if (peripheral == null || peripheral != Peripheral)
                return;

            if (e.Error == null)
                OnCharacteristicWrite(this, new BleCharacteristicWriteEventArgs(e.Characteristic, BleGattOperationState.Success));
            else
                OnCharacteristicWrite(this, new BleCharacteristicWriteEventArgs(e.Characteristic, BleGattOperationState.Failure));
        }
Exemple #18
0
 private void OnUpdatedValue(object sender, CBCharacteristicEventArgs args)
 {
     var characteristic = args.Characteristic;
     if (characteristic.IsUuidEqual(BluetoothServiceUuid.NameCharacteristic))
     {
         OnNameUpdate(characteristic.Value);
     }
     if (characteristic.IsUuidEqual(BluetoothServiceUuid.StatusCharacteristic))
     {
         OnStatusUpdate(characteristic.Value);
     }
 }
Exemple #19
0
        void WroteCharacteristicValue(object sender, CBCharacteristicEventArgs e)
        {
            if (e.Error != null)
            {
                FailureEventHandler?.Invoke(this, new BluetoothFailureEventArgs(e.Error.Description));
                return;
            }

            var characteristic = new Characteristic(e.Characteristic.UUID.Uuid);

            WroteCharacteristicValueEventHandler?.Invoke(this, new WroteCharacteristicValueEventArgs(characteristic));
        }
        private void OnWroteCharacteristicValue(object sender, CBCharacteristicEventArgs e)
        {
            if (!ReferenceEquals(e.Characteristic, _characteristic))
            {
                return;
            }

            if (e.Error != null)
            {
                RaiseWriteFailed(e.Error.ToShared());
            }
            else
            {
                RaiseValueWritten();
            }
        }
Exemple #21
0
        void UpdatedCharacterteristicValue(object sender, CBCharacteristicEventArgs e)
        {
            if (e.Error != null)
            {
                FailureEventHandler?.Invoke(this, new BluetoothFailureEventArgs(e.Error.Description));
                return;
            }

            Console.Error.WriteLine($"Got characteristic value for {e.Characteristic.UUID.Uuid}");
            var uuid           = e.Characteristic.UUID.Uuid;
            var nsDataValue    = e.Characteristic.Value;
            var characteristic = new Characteristic(uuid);
            var value          = nsDataValue.ToArray();

            ReadCharacteristicValueEventHandler?.Invoke(this, new ReadCharacteristicValueEventArgs(characteristic, value));
        }
        private void OnUpdatedNotificationState(object sender, CBCharacteristicEventArgs e)
        {
            if (!ReferenceEquals(e.Characteristic, _characteristic))
            {
                return;
            }

            if (e.Error != null)
            {
                RaiseSetNotificationFailed(e.Error.ToShared());
            }
            else
            {
                RaiseNotificationSet();
            }
        }
        private void OnUpdatedCharacterteristicValue(object sender, CBCharacteristicEventArgs e)
        {
            // iOS 中无法区分数据更新来源于 Read 还是 Notify,所以统一触发 ValueChanged 事件
            if (!ReferenceEquals(e.Characteristic, _characteristic))
            {
                return;
            }

            if (e.Error != null)
            {
                RaiseReadFailed(e.Error.ToShared());
            }
            else
            {
                RaiseValueChanged();
            }
        }
        private void OnDiscoveredDescriptor(object sender, CBCharacteristicEventArgs e)
        {
            if (!ReferenceEquals(e.Characteristic, _characteristic))
            {
                return;
            }

            if (e.Error != null)
            {
                RaiseDiscoverDescriptorsFailed(e.Error.ToShared());
            }
            else
            {
                var descriptors = _characteristic
                                  .Descriptors
                                  .Select(d => new BLEDescriptor(PeripheralWrapper, d))
                                  .ToList();
                RaiseDescriptorsDiscovered(descriptors);
            }
        }
		// continues to listen indefinitely
		void UpdatedNotify(object sender, CBCharacteristicEventArgs e) {
			this.ValueUpdated (this, new CharacteristicReadEventArgs () {
				Characteristic = new Characteristic(e.Characteristic, _parentDevice)
			});
		}
		// removes listener after first response received
		void UpdatedRead (object sender, CBCharacteristicEventArgs e) {
			this.ValueUpdated (this, new CharacteristicReadEventArgs () {
				Characteristic = new Characteristic(e.Characteristic, _parentDevice)
			});
			_parentDevice.UpdatedCharacterteristicValue -= UpdatedRead;
		}
 private void UpdatedNotify(object sender, CBCharacteristicEventArgs e)
 {
     if (e.Characteristic.UUID == _nativeCharacteristic.UUID)
     {
         ValueUpdated?.Invoke(this, new CharacteristicUpdatedEventArgs(this));
     }
 }
		void UpdatedNotificationState(object sender, CBCharacteristicEventArgs e)
		{
			Console.WriteLine("Notification state event " + this._nativeCharacteristic);
			this.NotificationStateValueUpdated(this, new CharacteristicReadEventArgs()
			{
				Characteristic = new Characteristic(e.Characteristic, _parentDevice)
			});
		}
Exemple #29
0
 private void OnUpdatedCharacterteristicValue(object sender, CBCharacteristicEventArgs e)
 => _wes.RaiseEvent(nameof(UpdatedCharacterteristicValue), sender, e);
Exemple #30
0
 void device_DiscoveredDescriptor(object sender, CBCharacteristicEventArgs e)
 {
     _descriptorDiscovered.Set();
 }
 private void OnUpdatedNotificationState(object sender, CBCharacteristicEventArgs args)
 {
     if (args.Error == null)
     {
         Debug.WriteLine("Bluetooth: Successfully Subscribed to characteristic");
         _discoveryTaskSource.TrySetResult(null);
     }
     else
     {
         _discoveryTaskSource.TrySetException(new Exception("Bluetooth: Failed to subscribe to service characteristic"));
     }
 }
Exemple #32
0
 private void OnUpdatedNotificationState(object sender, CBCharacteristicEventArgs e)
 => _wes.RaiseEvent(nameof(UpdatedNotificationState), sender, e);
 private void PeripheralOnUpdatedNotificationState(object sender, CBCharacteristicEventArgs cbCharacteristicEventArgs)
 {
     NotificationStateChanged?.Invoke(this, new CharacteristicNotificationStateEventArgs(this, cbCharacteristicEventArgs.Error == null));
 }
 private void UpdatedCharacteristicValue(object sender, CBCharacteristicEventArgs e)
 {
     ValueUpdated(this, new CharacteristicReadEventArgs(this));
 }
 private void _peripheral_UpdatedCharacterteristicValue(object sender, CBCharacteristicEventArgs e)
 {
     valueChanged?.Invoke(this, new GattValueChangedEventArgs(e.Characteristic.Value.ToArray(), DateTimeOffset.Now));
 }
		private void UpdatedCharacteristicValue(object sender, CBCharacteristicEventArgs e)
		{
			if (e.Characteristic.UUID == _nativeCharacteristic.UUID)
			{
				ValueUpdated(this, new CharacteristicReadEventArgs(this));
			}
		}
Exemple #37
0
 private void OnDiscoveredDescriptor(object sender, CBCharacteristicEventArgs e)
 => _wes.RaiseEvent(nameof(DiscoveredDescriptor), sender, e);