示例#1
0
        /// <summary>
        /// Sets the cell current.
        /// </summary>
        /// <param name="current">The current.</param>
        /// <exception cref="System.NullReferenceException">Not connected to a device</exception>
        /// <exception cref="System.Exception">Device must be in idle mode for manual control</exception>
        public async Task SetCellCurrentAsync(float current)
        {
            if (_comm == null)
            {
                throw new NullReferenceException("Not connected to a device");
            }
            if (await _comm.GetStateAsync() != CommManager.DeviceState.Idle)
            {
                throw new Exception("Device must be in idle mode for manual control");
            }
            if (!Capabilities.IsGalvanostat)
            {
                throw new Exception("Device does not support Galvanostat mode");
            }

            await RunAsync(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 (await _comm.GetStateAsync() != CommManager.DeviceState.Idle)
                {
                    throw new Exception("Device must be in idle mode for manual control");
                }
                if (!Capabilities.IsGalvanostat)
                {
                    throw new Exception("Device does not support Galvanostat mode");
                }
                await _comm.SetCurrentAsync(current);
            });
        }