Ejemplo n.º 1
0
        //public static void HeatUntilPlateau()
        //{
        //    RecordCurrentState();

        //    PressureRegulator.RunWorkerAsync();
        //    ElementRegulator.RunWorkerAsync();

        //    CurrentState.PlateauTemp = 0;
        //    decimal StartTemp = CurrentRun.First().rrColumnHeadTemp;
        //    decimal LastDelta = 0M;
        //    decimal TotalDelta = 0M;


        //    while (!CurrentState.StillEmpty &&  !CurrentState.RVFull && (CurrentState.ColumnTemp <= StartTemp * 1.1M || CurrentRun.Count < 20))
        //    {
        //        if (CurrentState.ColumnTemp > StartTemp)
        //        {
        //            RecordCurrentState();
        //        }
        //        Thread.Sleep(RefreshRate);
        //    }

        //    while ((!CurrentState.StillEmpty && !CurrentState.RVFull && (LastDelta >= 0.02M) || TotalDelta < 0.25M))
        //    {
        //       decimal Temp1 = CurrentRun[CurrentRun.Count - 1].rrColumnHeadTemp;
        //       decimal Temp2 = CurrentRun[CurrentRun.Count - 20].rrColumnHeadTemp;

        //        LastDelta = Temp2 != 0 ? ((Temp2 - Temp1) / Temp2) : 0;
        //        if (Temp2 > Temp1)
        //        { TotalDelta = Temp2 != 0 ? ((Temp2 - StartTemp) / Temp2) : 0; }

        //        RecordCurrentState();
        //        Thread.Sleep(RefreshRate);
        //    }
        //}

        public static void Distill()
        {
            PressureRegulator.RunWorkerAsync();
            ElementRegulator.RunWorkerAsync();
            //CurrentState.PlateauTemp = CurrentRun.Last().rrColumnHeadTemp;
            BackGroundWorkers.EnableRelay(SystemProperties.CoolantPump);

            //Keep distilling as long as the theoretical boiling point is not overran allowing for a 2% margin of error in calculation
            while (!CurrentState.StillEmpty && !CurrentState.RVFull && CurrentState.ColumnTemp <= CurrentState.TheoreticalBoilingPoint * 1.02M)
            {
                RecordCurrentState();
                Thread.Sleep(RefreshRate);
            }

            BackGroundWorkers.DisableRelay(SystemProperties.StillElement);
            CurrentState.ElementOn = false;
        }
Ejemplo n.º 2
0
        public static void FillStill()
        {
            if (CurrentState.StillFull == false)
            {
                BackGroundWorkers.EnableRelay(SystemProperties.StillFillValve);
                CurrentState.StillValveOpen = true;
                Thread.Sleep(3000); //Wait 3 seconds for the valve to open

                BackGroundWorkers.EnableRelay(SystemProperties.StillFluidPump);
                CurrentState.StillPumpOn = true;

                while (CurrentState.StillFull == false)
                {
                    Thread.Sleep(RefreshRate);
                }

                BackGroundWorkers.DisableRelay(SystemProperties.StillFillValve);
                CurrentState.StillValveOpen = false;

                BackGroundWorkers.DisableRelay(SystemProperties.StillFluidPump);
                CurrentState.StillPumpOn = false;
            }
        }
Ejemplo n.º 3
0
        public static void Start()
        {
            Dispatcher StillControllerDispatcher = Dispatcher.CurrentDispatcher;

            BackGroundWorkers.InitializeDI2008();

            SystemMonitor     = BackGroundWorkers.InitializeSystemMonitor(StillControllerDispatcher);
            PressureRegulator = BackGroundWorkers.InitializePressureWorker();
            ElementRegulator  = BackGroundWorkers.InitializeElementWorker();

            StillRegulator = new BackgroundWorker();
            StillRegulator.WorkerSupportsCancellation = true;
            StillRegulator.DoWork += new DoWorkEventHandler((state, args) =>

            {
                while (true)
                {
                    var Header           = new RunHeader();
                    Header.rhStart       = DateTime.Now;
                    Header.rhEnd         = DateTime.Now;
                    Header.rhComplete    = false;
                    Header.rhAvgPressure = 0;

                    Context.RunHeaders.Add(Header);
                    Context.SaveChanges();

                    CurrentState.RunID = Header.rhID;

                    if (CurrentState.Run != true)
                    {
                        break;
                    }

                    while (CurrentState.ColumnTemp == 0)
                    {
                        Thread.Sleep(250);
                    }

                    FillStill();
                    CurrentState.Phase = 1;

                    Distill();
                    CurrentState.Phase = 2;

                    DrainVessels();

                    Header.rhComplete    = true;
                    Header.rhEnd         = DateTime.Now;
                    Header.rhAvgPressure = CurrentRun.Select(i => i.rrPressure).Average();
                    Context.RunRecords.AddRange(CurrentRun);

                    Context.SaveChanges();
                    CurrentRun.Clear();

                    CurrentState.Phase = 0;
                }
            });

            SystemMonitor.RunWorkerAsync();
            StillRegulator.RunWorkerAsync();
        }