Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
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);
            }
        }