Ejemplo n.º 1
0
        /// <summary>
        /// Reads the cell potential.
        /// </summary>
        /// <returns></returns>
        /// <exception cref="NullReferenceException">Not connected to a device</exception>
        /// <exception cref="Exception">Device must be in idle mode for manual control</exception>
        public async Task <float> ReadCellPotentialAsync()
        {
            if (_comm == null)
            {
                throw new NullReferenceException("Not connected to a device");
            }
            if (_comm.State != CommManager.DeviceState.Idle)
            {
                throw new Exception("Device must be in idle mode for manual control");
            }

            return(await RunAsync <float>(async() =>
            {
                //Need to check again as the task can be scheduled to run at a later point after which this could have changed
                if (_comm == null)
                {
                    throw new NullReferenceException("Not connected to a device");
                }
                if (_comm.State != CommManager.DeviceState.Idle)
                {
                    throw new Exception("Device must be in idle mode for manual control");
                }
                return await _comm.GetPotentialAsync();
            }));
        }