Exemple #1
0
 private void NewCoreCommand(object sender, CoreCommand c)
 {
     lock (_lock) {
         _commandQueue.Enqueue(c);
         _commReset.Set();
     }
 }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        private CoreCommand GetNextCommand()
        {
            CoreCommand cmd = null;

            lock (_lock) {
                if (_commandQueue.Count > 0)
                {
                    cmd = _commandQueue.Dequeue();
                }
            }
            return(cmd);
        }
Exemple #3
0
        private void BtnStart_Click(object sender, EventArgs e)
        {
            if (!_TDKconnection.Any(b => b == true))
            {
                U.Logger.WriteLine($"TDK has no connections!");
                MessageBox.Show($"TDK has no connections!");
                return;
            }
            if (!_arduino.Connected)
            {
                U.Logger.WriteLine($"Arduino not connected!");
                MessageBox.Show($"Arduino not connected!");
                return;
            }

            CheckPorts();
            var tdks = _TDKS.Where(t => t.Cycling == true).ToList();

            if (tdks.Select(x => x.SampleName).Distinct().Count() != tdks.Count() && tdks.Count() > 1)
            {
                U.Logger.WriteLine($"Duplicate Sample Names Choosen!");
                MessageBox.Show($"Duplicate Sample Names Choosen!");
                return;
            }

            var startargs = new StartCyclingArgs(_TDKS.Where(t => t.Cycling == true).ToList(),
                                                 Double.Parse(txtBiasOn.Text), Double.Parse(txtBiasOff.Text),
                                                 Double.Parse(textBoxOverVoltage.Text));

            var start = new CoreCommand {
                Type      = U.CmdType.StartCycling,
                StartArgs = startargs
            };

            NewCoreCommand(this, start);

            // Disable GUI buttons from the GUI thread
            foreach (var chk in _checkBoxes)
            {
                chk.Enabled = false;
            }
            foreach (var temp in _tempSensors)
            {
                temp.Enabled = false;
            }
            foreach (var curr in _setCurrents)
            {
                curr.Enabled = false;
            }
            foreach (var load in _loadButtons)
            {
                load.Enabled = false;
            }
            foreach (var neww in _voc)
            {
                neww.Enabled = false;
            }
            foreach (var neww in _numCells)
            {
                neww.Enabled = false;
            }
            chkTemp.Enabled            = false;
            chkSmoke.Enabled           = false;
            btnStart.Enabled           = false;
            btnCheckConnection.Enabled = false;
            btnLoadSamples.Enabled     = false;
            btnClearSamples.Enabled    = false;
            buttonClearAlarms.Enabled  = false;

            // save GUI inputs to default settings
            Properties.Settings.Default.Operator       = txtOperator.Text;
            Properties.Settings.Default.BiasON         = txtBiasOn.Text;
            Properties.Settings.Default.BiasOFF        = txtBiasOff.Text;
            Properties.Settings.Default.BiasONTempSet  = txtCurrOnTempSet.Text;
            Properties.Settings.Default.BiasOFFTempSet = txtCurrOffTempSet.Text;
            Properties.Settings.Default.OverTempSet    = txtOverTempSet.Text;
            Properties.Settings.Default.OverSmokeSet   = txtSmokeOverSet.Text;
            Properties.Settings.Default.OverVoltage    = textBoxOverVoltage.Text;
            Properties.Settings.Default.PauseFanTime   = txtPauseFans.Text;
            var iii = 0;

            foreach (var chk in _checkBoxes)
            {
                Properties.Settings.Default.CheckBoxes[iii] = chk.Checked;
                iii++;
            }
            var ii = 0;

            foreach (object chk in chkTemp.Items)
            {
                Properties.Settings.Default.ActiveTemps[ii] = chkTemp.GetItemChecked(chkTemp.Items.IndexOf(chk));
                ii++;
            }
            ii = 0;
            foreach (object chk in chkSmoke.Items)
            {
                Properties.Settings.Default.ActiveSmokes[ii] = chkSmoke.GetItemChecked(chkSmoke.Items.IndexOf(chk));
                ii++;
            }
            Properties.Settings.Default.Save();
        }
Exemple #4
0
        /// <summary>
        /// Handles Core commands from the Controls modules or the GUI.
        /// </summary>
        private void HandleCommand(CoreCommand c)
        {
            if (c == null)
            {
                Info("Got null command");
                return;
            }
            switch (c.Type)
            {
            case U.CmdType.None:
                break;

            case U.CmdType.StartCycling:
                U.Logger.WriteLine($"Starting TDK Worker thread");
                NewCoreCommand(this, new CoreCommand {
                    Type = U.CmdType.UpdateHeartBeatPacket
                });
                _TDKWorker.RunWorkerAsync(c.StartArgs);
                break;

            case U.CmdType.UpdateUI:
                _commWorker.ReportProgress(5, c.StartArgs);
                break;

            case U.CmdType.StopCycling:
                _cycling.STOP    = true;
                _cycling.GUISTOP = true;
                break;

            case U.CmdType.CleanGUI:
                _commWorker.ReportProgress(1);
                break;

            case U.CmdType.RecievedPacket:
                // update GUI with temp/smoke/alarms
                _commWorker.ReportProgress(2, c.ArduinoArgs);

                // if cycling is running then update alarms/data
                var packet = _arduino._recievedPacket;
                if (_TDKWorker.IsBusy)
                {
                    _cycling.STOP      = packet.EMSSTOP;
                    _cycling.EMSSTOP   = packet.EMSSTOP;
                    _cycling._temps    = new List <double>(packet.TempList);
                    _cycling._smokeRaw = new List <double>(packet.SmokeList);
                }

                // update refs with smallest value then check over smoke
                UpdateSmokeRefs(packet.SmokeList);
                _cycling._smokeLevel = new List <double>(_smokeLevel);
                if (CheckSmokeOver(packet.SmokeList))
                {
                    _cycling.SMOKEALARM = true;
                    SMOKEALARM          = true;
                    U.Logger.WriteLine($"SMOKE ALARM frmMAIN!");
                }

                // check overTemp
                if (CheckTempOver(packet.TempList))
                {
                    _cycling.TEMPALARM = true;
                    TEMPALARM          = true;
                    U.Logger.WriteLine($"TEMP ALARM frmMAIN!");
                }

                labelTempAlarm.BackColor  = TEMPALARM ? Color.Red : Color.Empty;
                labelSmokeAlarm.BackColor = SMOKEALARM ? Color.Red : Color.Empty;
                SoundPlayer audio = new SoundPlayer(Properties.Resources.AircraftAlarm);
                if (SMOKEALARM || TEMPALARM)       //|| packet.EMSSTOP) {
                {
                    audio.Play();
                }
                else
                {
                    audio.Stop();
                }


                break;

            case U.CmdType.UpdateHeartBeatPacket:
                _commWorker.ReportProgress(3);
                break;

            case U.CmdType.CheckConnection:
                _connectionWorker.RunWorkerAsync();
                break;

            case U.CmdType.ArduinoConnectSuccess:
                Connected = true;
                break;
            }
        }