コード例 #1
0
        public async void Disconnect()
        {
            disconnecting = true;
            connected     = false;

            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;
                }
            }
        }
コード例 #2
0
        private async Task <bool> ConnectButtonService()
        {
            if (_buttonService == null)
            {
                _buttonService = new BleButtonService()
                {
                    Version = this.version
                };
                _buttonService.Error += OnServiceError;

                if (await _buttonService.ConnectAsync(deviceInfo.ContainerId))
                {
                    _buttonService.ConnectionChanged += OnConnectionChanged;
                    return(true);
                }
                _buttonService.Error -= OnServiceError;
                _buttonService        = null;
                return(false);
            }
            return(true);
        }