Example #1
0
 // Check if all services chars and descs have been discovered
 // All chars must be discovered before the client can subscribe to notifications (this is solution on iOS and macOS)
 private void allDiscovered()
 {
     if (charCallCount <= completedChar && incCallCount <= completedInc && descCallCount <= completedDesc)
     {
         callback.onConnectToDevice(connectedPeripheral.Identifier.AsString().ToUpper(), connectedPeripheral.Name, true);
     }
 }
Example #2
0
        private async Task _connect(string deviceAddress)
        {
            BluetoothLEDevice        device = devices.First(f => (f.BluetoothAddress + "").ToUpper().Equals(deviceAddress.ToUpper()));
            GattDeviceServicesResult result = await device.GetGattServicesAsync(BluetoothCacheMode.Uncached);

            if (result.Status == GattCommunicationStatus.Success)
            {
                _isConnected    = true;
                connectedDevice = device;
                device.ConnectionStatusChanged += ConnectionStatusChanged;
                foreach (GattDeviceService service in result.Services)
                {
                    await AddService(service);
                }
                callback.onConnectToDevice((device.BluetoothAddress + "").ToUpper(), device.Name, true);
            }
            else
            {
                callback.onConnectToDevice((device.BluetoothAddress + "").ToUpper(), device.Name, false);
            }
        }