public void ThrowsWhenIndexIsInvalid() { var fanCfg = new FanConfiguration(); var cfg = new FanControlConfigV2() { EcPollInterval = 100, FanConfigurations = { fanCfg } }; var filter = A.Fake <ITemperatureFilter>(); A.CallTo(() => filter.FilterTemperature(A <double> .Ignored)).ReturnsLazily((double x) => x); var ec = A.Fake <IEmbeddedController>(); A.CallTo(() => ec.IsInitialized).Returns(true); A.CallTo(() => ec.AcquireLock(A <int> .Ignored)).Returns(true); var tempMon = A.Fake <ITemperatureMonitor>(); A.CallTo(() => tempMon.IsInitialized).Returns(true); using (var fanControl = new FanControl(cfg, filter, ec, tempMon)) { var exception = Record.Exception(() => fanControl.SetTargetFanSpeed(123, 12)); Assert.NotNull(exception); Assert.IsType <IndexOutOfRangeException>(exception); } }
public void SetConfig(string configUniqueId) { if (!this.disposed) { var cfgMan = new FanControlConfigManager(ConfigsDirectory); if (!cfgMan.Contains(configUniqueId)) { throw new ArgumentException("The specified config does not exist."); } else { ServiceSettings.Default.SelectedConfigId = configUniqueId; ServiceSettings.Save(); if (this.fanControl != null) { this.fanControl.Dispose(); this.fanControl = null; } Start(); } } }
public ClevoBridge() { _Wmi = new WmiProvider(_WmiPath, _WmiQuery); KeyboardLed = new KeyboardLedControl(this); Fan = new FanControl(this); Sensor = new SensorControl(); // this); }
public async Task CallsSetTargetSpeed(float speed) { var fanCfg1 = new FanConfiguration(); var fanCfg2 = new FanConfiguration(); var cfg = new FanControlConfigV2() { EcPollInterval = 100, FanConfigurations = { fanCfg1, fanCfg2 } }; var filter = A.Fake <ITemperatureFilter>(); A.CallTo(() => filter.FilterTemperature(A <double> .Ignored)).ReturnsLazily((double x) => x); var ec = A.Fake <IEmbeddedController>(); A.CallTo(() => ec.IsInitialized).Returns(true); A.CallTo(() => ec.AcquireLock(A <int> .Ignored)).Returns(true); var tempMon = A.Fake <ITemperatureMonitor>(); A.CallTo(() => tempMon.IsInitialized).Returns(true); var fan1 = A.Fake <Fan>(opt => opt.WithArgumentsForConstructor( new object[] { ec, fanCfg1, 70, false })); A.CallTo(() => fan1.GetCurrentSpeed()).Returns(0); var fan2 = A.Fake <Fan>(opt => opt.WithArgumentsForConstructor( new object[] { ec, fanCfg2, 70, false })); A.CallTo(() => fan2.GetCurrentSpeed()).Returns(0); var tsc = new TaskCompletionSource <bool>(); Task <bool> task = tsc.Task; var fanControl = new FanControl(cfg, filter, ec, tempMon, new[] { fan1, fan2 }); fanControl.EcUpdated += (s, e) => { tsc.TrySetResult(true); }; fanControl.SetTargetFanSpeed(speed, 0); fanControl.SetTargetFanSpeed(speed, 1); fanControl.Start(false); Assert.True(fanControl.Enabled, nameof(fanControl.Enabled)); await Task.WhenAny(task, Task.Delay(cfg.EcPollInterval * 3)); Assert.True(task.IsCompleted, nameof(task.IsCompleted)); A.CallTo(() => fan1.SetTargetSpeed(speed, A <float> .Ignored, false)) .MustHaveHappened(); A.CallTo(() => fan2.SetTargetSpeed(speed, A <float> .Ignored, false)) .MustHaveHappened(); }
public void SelectFanControl(string fcName) { if (String.IsNullOrEmpty(fcName)) return; var fullFcName = "emDomoSim.FanControlPrograms." + fcName; var fanControl = Activator.CreateInstance(Type.GetType(fullFcName)); if (fanControl is FanControl) { fan_ = (FanControl)fanControl; } }
public void SelectFanControl(string fcName) { if (String.IsNullOrEmpty(fcName)) { return; } var fullFcName = "emDomoSim.FanControlPrograms." + fcName; var fanControl = Activator.CreateInstance(Type.GetType(fullFcName)); if (fanControl is FanControl) { fan_ = (FanControl)fanControl; } }
private void TestFan(object sender, EventArgs e) { Core.IsBlock = true; FanControl.SetMotherboardControl(Fan.RamFan, false); FanControl.SetSpeed(Fan.RamFan, 50); FanControl.TimeStepping = 0; FanControl.SendPaket(); Thread.Sleep(2000); FanControl.SetSpeed(Fan.RamFan, 0); FanControl.SetMotherboardControl(Fan.RamFan, Config.Setting.RamFan.MotherboardControl); FanControl.SendPaket(); FanControl.TimeStepping = Config.Setting.TimeUpdate; Core.IsBlock = false; }
public void Dispose() { if (!this.disposed) { this.disposed = true; if (this.fanControl != null) { this.fanControl.Dispose(); this.fanControl = null; } GC.SuppressFinalize(this); } }
private static bool TryInitializeFanControl(FanControlConfigV2 cfg, out FanControl fanControl) { bool success = false; fanControl = null; try { float[] speeds = SettingsService.Settings.TargetFanSpeeds; if (speeds == null || speeds.Length != cfg.FanConfigurations.Count) { speeds = new float[cfg.FanConfigurations.Count]; for (int i = 0; i < speeds.Length; i++) { speeds[i] = FanControl.AutoFanSpeedPercentage; } SettingsService.Settings.TargetFanSpeeds = speeds; SaveSettings(); } fanControl = new FanControl(cfg); for (int i = 0; i < speeds.Length; i++) { fanControl.SetTargetFanSpeed(speeds[i], i); } success = true; } finally { if (!success && fanControl != null) { fanControl.Dispose(); fanControl = null; } } return(success); }
public void ResetsRegisterWriteConfigurations() { var fanCfg = new FanConfiguration(); var regWriteCfg = new RegisterWriteConfiguration() { Register = 123, Value = 12, ResetRequired = true, ResetValue = 24 }; var cfg = new FanControlConfigV2() { EcPollInterval = 100, FanConfigurations = { fanCfg }, RegisterWriteConfigurations = { regWriteCfg } }; var filter = A.Fake <ITemperatureFilter>(); A.CallTo(() => filter.FilterTemperature(A <double> .Ignored)).ReturnsLazily((double x) => x); var ec = A.Fake <IEmbeddedController>(); A.CallTo(() => ec.IsInitialized).Returns(true); A.CallTo(() => ec.AcquireLock(A <int> .Ignored)).Returns(true); A.CallTo(() => ec.ReadByte(A <byte> .Ignored)).Returns((byte)0); var tempMon = A.Fake <ITemperatureMonitor>(); A.CallTo(() => tempMon.IsInitialized).Returns(true); using (var fanControl = new FanControl(cfg, filter, ec, tempMon)) { fanControl.Start(false); fanControl.Stop(); A.CallTo(() => ec.WriteByte((byte)regWriteCfg.Register, (byte)regWriteCfg.ResetValue)) .MustHaveHappened(); } }
public void TriesToForceResetFans() { var fanCfg = new FanConfiguration() { ResetRequired = true }; var cfg = new FanControlConfigV2() { EcPollInterval = 100, FanConfigurations = { fanCfg } }; var filter = A.Fake <ITemperatureFilter>(); A.CallTo(() => filter.FilterTemperature(A <double> .Ignored)).ReturnsLazily((double x) => x); var ec = A.Fake <IEmbeddedController>(); A.CallTo(() => ec.IsInitialized).Returns(true); A.CallTo(() => ec.AcquireLock(A <int> .Ignored)).Returns(true); var tempMon = A.Fake <ITemperatureMonitor>(); A.CallTo(() => tempMon.IsInitialized).Returns(true); var fan = A.Fake <Fan>(opt => opt.WithArgumentsForConstructor( new object[] { ec, fanCfg, 70, false })); A.CallTo(() => fan.GetCurrentSpeed()).Returns(0); using (var fanControl = new FanControl(cfg, filter, ec, tempMon, new[] { fan })) { fanControl.Start(false); A.CallTo(() => ec.AcquireLock(A <int> .Ignored)).Returns(false); } A.CallTo(() => fan.Reset()).MustHaveHappened(); }
private void ListItemClicked(int position) { //this way we don't load twice, but you might want to modify this a bit. if (position == oldPosition) { return; } oldPosition = position; Android.Support.V4.App.Fragment fragment = null; switch (position) { case 0: fragment = Home.NewInstance(permissionGranted); SupportActionBar.Title = "Payload Sender"; break; case 1: fragment = FanControl.NewInstance(); SupportActionBar.Title = "Fan Control"; break; case 2: fragment = Settings.NewInstance(); SupportActionBar.Title = "Settings"; break; case 3: fragment = Credits.NewInstance(); SupportActionBar.Title = "Credits"; break; } SupportFragmentManager.BeginTransaction() .Replace(Resource.Id.content_frame, fragment) .Commit(); }
private void UpdateComponents() { textBox1.Text = Config.Setting.CpuFan.Profile[0].Temperature.ToString(); textBox2.Text = Config.Setting.CpuFan.Profile[0].Speed.ToString(CultureInfo.CurrentCulture); textBox4.Text = Config.Setting.CpuFan.Profile[1].Temperature.ToString(); textBox3.Text = Config.Setting.CpuFan.Profile[1].Speed.ToString(CultureInfo.CurrentCulture); textBox6.Text = Config.Setting.CpuFan.Profile[2].Temperature.ToString(); textBox5.Text = Config.Setting.CpuFan.Profile[2].Speed.ToString(CultureInfo.CurrentCulture); textBox8.Text = Config.Setting.CpuFan.Profile[3].Temperature.ToString(); textBox7.Text = Config.Setting.CpuFan.Profile[3].Speed.ToString(CultureInfo.CurrentCulture); textBox10.Text = Config.Setting.CpuFan.Profile[4].Temperature.ToString(); textBox9.Text = Config.Setting.CpuFan.Profile[4].Speed.ToString(CultureInfo.CurrentCulture); checkBox1.Checked = Config.Setting.CpuFan.MotherboardControl; textBox20.Text = Config.Setting.RamFan.Profile[0].Temperature.ToString(); textBox19.Text = Config.Setting.RamFan.Profile[0].Speed.ToString(CultureInfo.CurrentCulture); textBox18.Text = Config.Setting.RamFan.Profile[1].Temperature.ToString(); textBox17.Text = Config.Setting.RamFan.Profile[1].Speed.ToString(CultureInfo.CurrentCulture); textBox16.Text = Config.Setting.RamFan.Profile[2].Temperature.ToString(); textBox15.Text = Config.Setting.RamFan.Profile[2].Speed.ToString(CultureInfo.CurrentCulture); textBox14.Text = Config.Setting.RamFan.Profile[3].Temperature.ToString(); textBox13.Text = Config.Setting.RamFan.Profile[3].Speed.ToString(CultureInfo.CurrentCulture); textBox12.Text = Config.Setting.RamFan.Profile[4].Temperature.ToString(); textBox11.Text = Config.Setting.RamFan.Profile[4].Speed.ToString(CultureInfo.CurrentCulture); checkBox2.Checked = Config.Setting.RamFan.MotherboardControl; textBox23.Text = Config.Setting.PathApp1; textBox24.Text = Config.Setting.PathApp2; var ports = FanControl.GetPortList(); comboBox1.Items.Clear(); comboBox1.Items.AddRange(ports); comboBox1.SelectedIndex = Array.IndexOf(ports, Config.Setting.Port); textBox21.Text = Config.Setting.ChipsetFanSpeed.ToString(CultureInfo.CurrentCulture); textBox22.Text = Config.Setting.TimeUpdate.ToString(); }
private void Init() { //_bmp = new BMP085(); _display = new Display(); _ds18b20 = new DS18B20(0); //Console.WriteLine(string.Format("{0}", _ds18b20.GetValue())); _dth = new DTH(); _fanControl = new FanControl(); _hcsr = new HCSR04(); ConfigTimer(); }
private SimulationResults.FanControlResults SimulateDays(FanControl fc, int days) { float duration = 24.0f * days; //DoSimulateDay(); int dayInYear = DayInYearInput(); int warmUpDays = 7; // TODO: find shortest warm-up necessary, longer warm-up should make almost no difference var room = new RoomSimulator(); room.SelectFanControl(fc); room.SetTimeWithWarmUp(dayInYear, 0, warmUpDays); float deltaT = 0.05f; int nSamples = 0; float sumTemp = 0; float sumFanOn = 0; float sumTempOsc = 0; float lastTemp = room.GetRoomTemperature(); float lastMin = lastTemp; float lastMax = lastTemp; OscState oscState = OscState.None; float sumOsc = 0; int nOsc = 0; for (float t = 0; t < duration; t += deltaT) { RoomSimulator.State roomState = room.AdvanceTime(deltaT); nSamples++; float temp = roomState.roomTemperature_; sumTemp += temp; if (temp > lastTemp) { if (oscState == OscState.Down) { lastMin = lastTemp; } oscState = OscState.Up; } else { if (oscState == OscState.Up) { lastMax = lastTemp; sumOsc += lastMax - lastMin; nOsc++; } oscState = OscState.Down; } sumTempOsc += Math.Abs(temp - lastTemp)/deltaT; lastTemp = temp; sumFanOn += (room.FanStatus() ? 1 : 0) * deltaT; } return new SimulationResults.FanControlResults(fc.Name(), sumTemp / nSamples, sumTempOsc / nSamples, sumFanOn * 100 / duration); //return new SimulationResults.FanControlResults(fc.Name(), sumTemp / nSamples, sumOsc / nOsc, sumFanOn * 100 / duration); }
public void SelectFanControl(FanControl fc) { fan_ = fc; }
private Flowsheet SetFlowsheetContent(NewProcessSettings newProcessSettings, ApplicationPreferences appPrefs, ArrayList items, string flowsheetName) { Flowsheet flowsheet = null; IEnumerator e = items.GetEnumerator(); while (e.MoveNext()) { object obj = e.Current; if (obj is EvaporationAndDryingSystem) { EvaporationAndDryingSystem persisted = (EvaporationAndDryingSystem)obj; persisted.SetSystemFileName(flowsheetName); // call this before SetObjectData() persisted.SetObjectData(); flowsheet = new Flowsheet(newProcessSettings, appPrefs, persisted); } else if (obj is GasStreamControl) { GasStreamControl persistedCtrl = (GasStreamControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); DryingGasStream stream = flowsheet.EvaporationAndDryingSystem.GetGasStream(solvableName); GasStreamControl newCtrl = new GasStreamControl(flowsheet, new Point(0, 0), stream); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is MaterialStreamControl) { MaterialStreamControl persistedCtrl = (MaterialStreamControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); DryingMaterialStream stream = flowsheet.EvaporationAndDryingSystem.GetMaterialStream(solvableName); MaterialStreamControl newCtrl = new MaterialStreamControl(flowsheet, new Point(0, 0), stream); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is DryerControl) { DryerControl persistedCtrl = (DryerControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); Dryer uo = flowsheet.EvaporationAndDryingSystem.GetDryer(solvableName); DryerControl newCtrl = new DryerControl(flowsheet, new Point(0, 0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is HeatExchangerControl) { HeatExchangerControl persistedCtrl = (HeatExchangerControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); HeatExchanger uo = flowsheet.EvaporationAndDryingSystem.GetHeatExchanger(solvableName); HeatExchangerControl newCtrl = new HeatExchangerControl(flowsheet, new Point(0, 0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is CycloneControl) { CycloneControl persistedCtrl = (CycloneControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); Cyclone uo = flowsheet.EvaporationAndDryingSystem.GetCyclone(solvableName); CycloneControl newCtrl = new CycloneControl(flowsheet, new Point(0, 0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is EjectorControl) { EjectorControl persistedCtrl = (EjectorControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); Ejector uo = flowsheet.EvaporationAndDryingSystem.GetEjector(solvableName); EjectorControl newCtrl = new EjectorControl(flowsheet, new Point(0, 0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is WetScrubberControl) { WetScrubberControl persistedCtrl = (WetScrubberControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); WetScrubber uo = flowsheet.EvaporationAndDryingSystem.GetWetScrubber(solvableName); WetScrubberControl newCtrl = new WetScrubberControl(flowsheet, new Point(0, 0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is ScrubberCondenserControl) { ScrubberCondenserControl persistedCtrl = (ScrubberCondenserControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); ScrubberCondenser uo = flowsheet.EvaporationAndDryingSystem.GetScrubberCondenser(solvableName); ScrubberCondenserControl newCtrl = new ScrubberCondenserControl(flowsheet, new Point(0, 0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is MixerControl) { MixerControl persistedCtrl = (MixerControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); Mixer uo = flowsheet.EvaporationAndDryingSystem.GetMixer(solvableName); MixerControl newCtrl = new MixerControl(flowsheet, new Point(0, 0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is TeeControl) { TeeControl persistedCtrl = (TeeControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); Tee uo = flowsheet.EvaporationAndDryingSystem.GetTee(solvableName); TeeControl newCtrl = new TeeControl(flowsheet, new Point(0, 0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is FlashTankControl) { FlashTankControl persistedCtrl = (FlashTankControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); FlashTank uo = flowsheet.EvaporationAndDryingSystem.GetFlashTank(solvableName); FlashTankControl newCtrl = new FlashTankControl(flowsheet, new Point(0, 0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is FanControl) { FanControl persistedCtrl = (FanControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); Fan uo = flowsheet.EvaporationAndDryingSystem.GetFan(solvableName); FanControl newCtrl = new FanControl(flowsheet, new Point(0, 0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is ValveControl) { ValveControl persistedCtrl = (ValveControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); Valve uo = flowsheet.EvaporationAndDryingSystem.GetValve(solvableName); ValveControl newCtrl = new ValveControl(flowsheet, new Point(0, 0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is BagFilterControl) { BagFilterControl persistedCtrl = (BagFilterControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); BagFilter uo = flowsheet.EvaporationAndDryingSystem.GetBagFilter(solvableName); BagFilterControl newCtrl = new BagFilterControl(flowsheet, new Point(0, 0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is AirFilterControl) { AirFilterControl persistedCtrl = (AirFilterControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); AirFilter uo = flowsheet.EvaporationAndDryingSystem.GetAirFilter(solvableName); AirFilterControl newCtrl = new AirFilterControl(flowsheet, new Point(0, 0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is CompressorControl) { CompressorControl persistedCtrl = (CompressorControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); Compressor uo = flowsheet.EvaporationAndDryingSystem.GetCompressor(solvableName); CompressorControl newCtrl = new CompressorControl(flowsheet, new Point(0, 0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is HeaterControl) { HeaterControl persistedCtrl = (HeaterControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); Heater uo = flowsheet.EvaporationAndDryingSystem.GetHeater(solvableName); HeaterControl newCtrl = new HeaterControl(flowsheet, new Point(0, 0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is CoolerControl) { CoolerControl persistedCtrl = (CoolerControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); Cooler uo = flowsheet.EvaporationAndDryingSystem.GetCooler(solvableName); CoolerControl newCtrl = new CoolerControl(flowsheet, new Point(0, 0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is ElectrostaticPrecipitatorControl) { ElectrostaticPrecipitatorControl persistedCtrl = (ElectrostaticPrecipitatorControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); ElectrostaticPrecipitator uo = flowsheet.EvaporationAndDryingSystem.GetElectrostaticPrecipitator(solvableName); ElectrostaticPrecipitatorControl newCtrl = new ElectrostaticPrecipitatorControl(flowsheet, new Point(0, 0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is PumpControl) { PumpControl persistedCtrl = (PumpControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); Pump uo = flowsheet.EvaporationAndDryingSystem.GetPump(solvableName); PumpControl newCtrl = new PumpControl(flowsheet, new Point(0, 0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is RecycleControl) { RecycleControl persistedCtrl = (RecycleControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); Recycle uo = flowsheet.EvaporationAndDryingSystem.GetRecycle(solvableName); RecycleControl newCtrl = new RecycleControl(flowsheet, new Point(0, 0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is SolvableConnection) { SolvableConnection persistedDc = (SolvableConnection)obj; SolvableConnection dc = new SolvableConnection(flowsheet); dc.SetObjectData(persistedDc.SerializationInfo, persistedDc.StreamingContext); flowsheet.ConnectionManager.Connections.Add(dc); } else if (obj is FlowsheetPreferences) { FlowsheetPreferences flowsheetPrefs = obj as FlowsheetPreferences; flowsheetPrefs.SetObjectData(flowsheetPrefs.SerializationInfo, flowsheetPrefs.StreamingContext); flowsheet.BackColor = flowsheetPrefs.BackColor; } else if (obj is ProsimoUI.CustomEditor.CustomEditor) { ProsimoUI.CustomEditor.CustomEditor persistedEditor = (ProsimoUI.CustomEditor.CustomEditor)obj; flowsheet.CustomEditor.SetObjectData(persistedEditor.SerializationInfo, persistedEditor.StreamingContext); } } if (this.CheckFlowsheetVersion(items, flowsheet)) { flowsheet.IsDirty = false; } else { flowsheet = null; } return(flowsheet); }
private ArrayList GetFlowsheetContent(Flowsheet flowsheet) { ArrayList toSerializeItems = new ArrayList(); toSerializeItems.Add(flowsheet.EvaporationAndDryingSystem); // get all the flowsheet element controls IEnumerator e = flowsheet.Controls.GetEnumerator(); while (e.MoveNext()) { object obj = e.Current; if (obj is GasStreamControl) { GasStreamControl ctrl = (GasStreamControl)obj; toSerializeItems.Add(ctrl); } else if (obj is MaterialStreamControl) { MaterialStreamControl ctrl = (MaterialStreamControl)obj; toSerializeItems.Add(ctrl); } else if (obj is DryerControl) { DryerControl ctrl = (DryerControl)obj; toSerializeItems.Add(ctrl); } else if (obj is HeatExchangerControl) { HeatExchangerControl ctrl = (HeatExchangerControl)obj; toSerializeItems.Add(ctrl); } else if (obj is CycloneControl) { CycloneControl ctrl = (CycloneControl)obj; toSerializeItems.Add(ctrl); } else if (obj is EjectorControl) { EjectorControl ctrl = (EjectorControl)obj; toSerializeItems.Add(ctrl); } else if (obj is WetScrubberControl) { WetScrubberControl ctrl = (WetScrubberControl)obj; toSerializeItems.Add(ctrl); } else if (obj is ScrubberCondenserControl) { ScrubberCondenserControl ctrl = (ScrubberCondenserControl)obj; toSerializeItems.Add(ctrl); } else if (obj is MixerControl) { MixerControl ctrl = (MixerControl)obj; toSerializeItems.Add(ctrl); } else if (obj is TeeControl) { TeeControl ctrl = (TeeControl)obj; toSerializeItems.Add(ctrl); } else if (obj is FlashTankControl) { FlashTankControl ctrl = (FlashTankControl)obj; toSerializeItems.Add(ctrl); } else if (obj is FanControl) { FanControl ctrl = (FanControl)obj; toSerializeItems.Add(ctrl); } else if (obj is ValveControl) { ValveControl ctrl = (ValveControl)obj; toSerializeItems.Add(ctrl); } else if (obj is BagFilterControl) { BagFilterControl ctrl = (BagFilterControl)obj; toSerializeItems.Add(ctrl); } else if (obj is AirFilterControl) { AirFilterControl ctrl = (AirFilterControl)obj; toSerializeItems.Add(ctrl); } else if (obj is CompressorControl) { CompressorControl ctrl = (CompressorControl)obj; toSerializeItems.Add(ctrl); } else if (obj is HeaterControl) { HeaterControl ctrl = (HeaterControl)obj; toSerializeItems.Add(ctrl); } else if (obj is CoolerControl) { CoolerControl ctrl = (CoolerControl)obj; toSerializeItems.Add(ctrl); } else if (obj is ElectrostaticPrecipitatorControl) { ElectrostaticPrecipitatorControl ctrl = (ElectrostaticPrecipitatorControl)obj; toSerializeItems.Add(ctrl); } else if (obj is PumpControl) { PumpControl ctrl = (PumpControl)obj; toSerializeItems.Add(ctrl); } else if (obj is RecycleControl) { RecycleControl ctrl = (RecycleControl)obj; toSerializeItems.Add(ctrl); } } // get all the connections e = flowsheet.ConnectionManager.Connections.GetEnumerator(); while (e.MoveNext()) { SolvableConnection dc = (SolvableConnection)e.Current; toSerializeItems.Add(dc); } // get the flowsheet preferences FlowsheetPreferences flowsheetPrefs = new FlowsheetPreferences(flowsheet); toSerializeItems.Add(flowsheetPrefs); // get the custom editor (we persist only the ID of the variables) toSerializeItems.Add(flowsheet.CustomEditor); // get the flowsheet version toSerializeItems.Add(flowsheet.Version); return(toSerializeItems); }
private static bool TryInitializeFanControl(FanControlConfigV2 cfg, out FanControl fanControl) { bool success = false; fanControl = null; try { float[] speeds = ServiceSettings.Default.TargetFanSpeeds; fanControl = new FanControl(cfg); if (speeds == null || speeds.Length != cfg.FanConfigurations.Count) { speeds = new float[cfg.FanConfigurations.Count]; for (int i = 0; i < speeds.Length; i++) { speeds[i] = FanControl.AutoFanSpeedPercentage; } } if (speeds != null && speeds.Length == fanControl.FanInformation.Count) { for (int i = 0; i < speeds.Length; i++) { fanControl.SetTargetFanSpeed(speeds[i], i); } } success = true; } finally { if (!success && fanControl != null) { fanControl.Dispose(); fanControl = null; } } return success; }
private SimulationResults.FanControlResults SimulateDays(FanControl fc, int days) { float duration = 24.0f * days; //DoSimulateDay(); int dayInYear = DayInYearInput(); int warmUpDays = 7; // TODO: find shortest warm-up necessary, longer warm-up should make almost no difference var room = new RoomSimulator(); room.SelectFanControl(fc); room.SetTimeWithWarmUp(dayInYear, 0, warmUpDays); float deltaT = 0.05f; int nSamples = 0; float sumTemp = 0; float sumFanOn = 0; float sumTempOsc = 0; float lastTemp = room.GetRoomTemperature(); float lastMin = lastTemp; float lastMax = lastTemp; OscState oscState = OscState.None; float sumOsc = 0; int nOsc = 0; for (float t = 0; t < duration; t += deltaT) { RoomSimulator.State roomState = room.AdvanceTime(deltaT); nSamples++; float temp = roomState.roomTemperature_; sumTemp += temp; if (temp > lastTemp) { if (oscState == OscState.Down) { lastMin = lastTemp; } oscState = OscState.Up; } else { if (oscState == OscState.Up) { lastMax = lastTemp; sumOsc += lastMax - lastMin; nOsc++; } oscState = OscState.Down; } sumTempOsc += Math.Abs(temp - lastTemp) / deltaT; lastTemp = temp; sumFanOn += (room.FanStatus() ? 1 : 0) * deltaT; } return(new SimulationResults.FanControlResults(fc.Name(), sumTemp / nSamples, sumTempOsc / nSamples, sumFanOn * 100 / duration)); //return new SimulationResults.FanControlResults(fc.Name(), sumTemp / nSamples, sumOsc / nOsc, sumFanOn * 100 / duration); }