public IAsyncOperationContext BeginRampToTemperature(Value <Unit.Temperature> targetTemperature, Value <Unit.TemperatureRate> rampRateAbs, ReadOnlyRange <Unit.Temperature> settlingBand, TimeSpan settlingTime) { if (_operationService.GetOperationStatus()) { return(_operationService); } if (_operationService.GetCurrentTemperature() < targetTemperature) { var task = _operationService.RampingUpAsync(targetTemperature, rampRateAbs, settlingBand, settlingTime); try { task.ConfigureAwait(false); } catch (Exception e) { Console.WriteLine(e.Message); } } else if (_operationService.GetCurrentTemperature() > targetTemperature) { var task = _operationService.RampingDownAsync(targetTemperature, rampRateAbs, settlingBand, settlingTime); try { task.ConfigureAwait(false); } catch (Exception e) { Console.WriteLine(e.Message); } } return(_operationService); }
public async Task TestRampingDown() { var operationService = new AsyncOperationService(); var targetTemperature = new Value <Unit.Temperature>(3.0, Unit.Temperature.TemperatureInDegC); var rampRate = new Value <Unit.TemperatureRate>(2.5, Unit.TemperatureRate.TemperatureRateInDegCPerMinute); var minBand = new Value <Unit.Temperature>(targetTemperature.Number - 1, Unit.Temperature.TemperatureInDegC); var maxBand = new Value <Unit.Temperature>(targetTemperature.Number + 1, Unit.Temperature.TemperatureInDegC); var band = new ReadOnlyRange <Unit.Temperature>(minBand, maxBand); var time = TimeSpan.FromMinutes(5); await operationService.RampingDownAsync(targetTemperature, rampRate, band, time); var currentTemp = operationService.GetCurrentTemperature().Number; Assert.AreEqual(3.0, currentTemp); }
public void TestCancelRamp() { var operationService = new AsyncOperationService(); var targetTemperature = new Value <Unit.Temperature>(69.56, Unit.Temperature.TemperatureInDegC); var rampRate = new Value <Unit.TemperatureRate>(2.5, Unit.TemperatureRate.TemperatureRateInDegCPerMinute); var minBand = new Value <Unit.Temperature>(targetTemperature.Number - 3, Unit.Temperature.TemperatureInDegC); var maxBand = new Value <Unit.Temperature>(targetTemperature.Number + 3, Unit.Temperature.TemperatureInDegC); var band = new ReadOnlyRange <Unit.Temperature>(minBand, maxBand); var time = TimeSpan.FromMinutes(5); Task.Run(async() => { await operationService.RampingDownAsync(targetTemperature, rampRate, band, time); }); operationService.CancelOperation(); Assert.IsFalse(operationService.GetOperationStatus()); Assert.AreNotEqual(69.56, operationService.GetCurrentTemperature()); }