private async Task <bool> ConnectIRTemperatureService() { if (_tempService == null) { _tempService = new BleIRTemperatureService() { Version = this.version }; _tempService.Error += OnServiceError; if (await _tempService.ConnectAsync(deviceInfo.ContainerId)) { _tempService.ConnectionChanged += OnConnectionChanged; return(true); } _tempService.Error -= OnServiceError; _tempService = null; return(false); } return(true); }
public async void Disconnect() { disconnecting = true; connected = false; if (_emgNode2Service != null) { using (_emgNode2Service) { try { _emgNode2Service.Error -= OnServiceError; _emgNode2Service.ConnectionChanged -= OnConnectionChanged; await _emgNode2Service.StopReading(); } catch { } _emgNode2Service = null; } } if (_barometerService != null) { using (_barometerService) { try { _barometerService.Error -= OnServiceError; _barometerService.ConnectionChanged -= OnConnectionChanged; await _barometerService.StopReading(); } catch { } _barometerService = null; } } if (_tempService != null) { using (_tempService) { try { _tempService.Error -= OnServiceError; _tempService.ConnectionChanged -= OnConnectionChanged; await _tempService.StopReading(); } catch { } _tempService = null; } } if (_buttonService != null) { using (_buttonService) { _buttonService.Error -= OnServiceError; _buttonService.ConnectionChanged -= OnConnectionChanged; _buttonService = null; } } if (_accelService != null) { using (_accelService) { try { _accelService.Error -= OnServiceError; _accelService.ConnectionChanged -= OnConnectionChanged; await _accelService.StopReading(); } catch { } _accelService = null; } } if (_gyroService != null) { using (_gyroService) { try { _gyroService.Error -= OnServiceError; _gyroService.ConnectionChanged -= OnConnectionChanged; await _gyroService.StopReading(); } catch { } _gyroService = null; } } if (_magService != null) { using (_magService) { try { _magService.Error -= OnServiceError; _magService.ConnectionChanged -= OnConnectionChanged; await _magService.StopReading(); } catch { } _magService = null; } } if (_humidityService != null) { using (_humidityService) { try { _humidityService.Error -= OnServiceError; _humidityService.ConnectionChanged -= OnConnectionChanged; await _humidityService.StopReading(); } catch { } _humidityService = null; } } if (_barometerService != null) { using (_barometerService) { try { _barometerService.Error -= OnServiceError; _barometerService.ConnectionChanged -= OnConnectionChanged; await _barometerService.StopReading(); } catch { } _barometerService = null; } } if (_motionService != null) { using (_motionService) { try { _motionService.Error -= OnServiceError; _motionService.ConnectionChanged -= OnConnectionChanged; await _motionService.StopReading(); } catch { } _motionService = null; } } if (_lightService != null) { using (_lightService) { try { _lightService.Error -= OnServiceError; _lightService.ConnectionChanged -= OnConnectionChanged; await _lightService.StopReading(); } catch { } _lightService = null; } } }