public override void OnServicesDiscovered(BluetoothGatt gatt, GattStatus status)
        {
            base.OnServicesDiscovered(gatt, status);

            if (status == GattStatus.Success)
            {
                foreach (BluetoothGattService service in gatt.Services)
                {
                    foreach (BluetoothGattCharacteristic characteristic in service.Characteristics)
                    {
                        BluetoothServiceDevice b = new BluetoothServiceDevice();
                        b.service        = service;
                        b.characteristic = characteristic;
                        b.gatt           = gatt;
                        storeService.Add(b);
                    }
                }
                if (this.Discovered_Event != null)
                {
                    this.Discovered_Event(storeService);
                }
            }
        }
Esempio n. 2
0
        //Call Back BLE onDiscovered
        private void Blecallback_Discovered_Event(List <BluetoothServiceDevice> obj)
        {
            bool findDeviceJOY       = false;
            bool findDeviceTELEMETRY = false;

            BluetoothGattCharacteristic clientchar = null;

            //Verifica Servizi se sono compatibili
            foreach (BluetoothServiceDevice s in obj)
            {
                string myservice = myUUID.DEVICE_SERVICE_UUID.Replace("-", "").ToLower();
                if (s.service.Uuid.ToString().Replace("-", "").ToLower() == myservice)
                {
                    if (s.characteristic.Uuid.ToString().Replace("-", "").ToLower() == myUUID.JOY_CHARACTERISTIC_CONFIG.Replace("-", "").ToLower())
                    {
                        findDeviceJOY = true;
                        if (joyBLE == null)
                        {
                            joyBLE = new BluetoothServiceDevice();
                        }
                        joyBLE.service        = s.service;
                        joyBLE.characteristic = s.characteristic;
                        joyBLE.gatt           = s.gatt;
                    }
                    else if (s.characteristic.Uuid.ToString().Replace("-", "").ToLower() == myUUID.TELEMETRY_CHARACTERISTIC_CONFIG.Replace("-", "").ToLower())
                    {
                        findDeviceTELEMETRY = true;
                        if (telemetryBLE == null)
                        {
                            telemetryBLE = new BluetoothServiceDevice();
                        }
                        telemetryBLE.service        = s.service;
                        telemetryBLE.characteristic = s.characteristic;
                        telemetryBLE.gatt           = s.gatt;
                    }
                }
            }

            if ((findDeviceJOY) && (findDeviceTELEMETRY))
            {
                //Richietsa Attivavazione Char Notification

                ble.CLoseAll_SetCharacteristicNotification();
                ble.SetCharacteristicNotification(telemetryBLE.gatt, telemetryBLE.characteristic, myUUID.CLIENT_UUID);
            }
            else
            {
                // **************************************************************************************************************************************************************************************************************************************************************

                /*              Handler mHandler = new Handler();
                 *              mHandler.PostDelayed(new Action(delegate {
                 *                  Finish();
                 *              }), 2000);
                 */
                if (obj != null)
                {
                    foreach (BluetoothServiceDevice s in obj)
                    {
                        if (s.gatt != null)
                        {
                            s.gatt.Disconnect();
                            s.gatt.Close();
                        }
                    }
                }
                activity.RunOnUiThread(() => Action_Error("Errore Connessione!!!"));
            }
        }