Example #1
0
        public async Task <bool> DisconnectDevice(SensorDevice sensorDevice)
        {
            // Check if correct device reference was provided.
            if (sensorDevice == null)
            {
                return(false);
            }

            _isBusy = true;

            // Get type of device.
            DeviceType deviceType = sensorDevice.Type;

            // Clear connected device.
            DeviceSlot occupingSlot = _deviceSlotService.GetSlotWithDevice(sensorDevice);

            if (occupingSlot == null)
            {
                _isBusy = false;
                return(false);
            }

            foreach (var outputID in occupingSlot.OutputDataIDs)
            {
                OutputData.Remove(outputID);
                _sensorDataService.RemoveFromDataBuffer(outputID);
            }

            _deviceSlotService.EmptySlot(occupingSlot.Index);
            await _adapter.DisconnectDeviceAsync(sensorDevice.Device);

            _isBusy = false;
            return(true);
        }