Esempio n. 1
0
 public ArduinoMachine()
 {
     _transmitPacket = new TransmitPacket("200", "200", "85", "25", "0", "0", "0000000000000000", "00000000", "0");
     Connected       = false;
 }
Esempio n. 2
0
 public void UpdateTransmit(TransmitPacket t, bool printPackets)
 {
     _transmitPacket = t;
     _printPackets   = printPackets;
 }
Esempio n. 3
0
        public frmMain()
        {
            InitializeComponent();
            Connected         = false;
            this.FormClosing += new FormClosingEventHandler(Form_Closing);
            TestDataEvent    += BQConn.QueueData;
            Directory.CreateDirectory(U.Logger.Dir);
            Directory.CreateDirectory(U.BackupDir);
            _commWorker.DoWork += RunCommMachine;
            _commWorker.WorkerReportsProgress = true;
            _commWorker.ProgressChanged      += UpdateUi;
            _commWorker.RunWorkerAsync();

            _TDKWorker.DoWork             += RunCurrentCycling;
            _TDKWorker.RunWorkerCompleted += CyclingComplete;

            _arduinoWorker.DoWork += RunArduinoLoop;
            _arduinoWorker.WorkerReportsProgress = true;
            _arduinoWorker.ProgressChanged      += UpdateHeartBeat;
            _arduinoWorker.RunWorkerAsync();

            _connectionWorker.DoWork             += CheckConnect;
            _connectionWorker.RunWorkerCompleted += ConnectComplete;

            _cycling.NewCoreCommand += NewCoreCommand;
            _arduino.NewCoreCommand += NewCoreCommand;


            _refSmokes = new List <double> {
                10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000
            };
            _smokeLevel = new List <double> {
                0, 0, 0, 0, 0, 0, 0, 0
            };
            _TDKconnection = new List <bool> {
                false, false, false, false, false, false,
                false, false, false, false, false, false,
            };
            _samples = new List <Label> {
                lblSample1, lblSample2, lblSample3, lblSample4,
                lblSample5, lblSample6, lblSample7, lblSample8, lblSample9, lblSample10, lblSample11, lblSample12
            };
            _checkBoxes = new List <CheckBox> {
                chkbxPort1, chkbxPort2, chkbxPort3,
                chkbxPort4, chkbxPort5, chkbxPort6, chkbxPort7, chkbxPort8, chkbxPort9,
                chkbxPort10, chkbxPort11, chkbxPort12
            };
            _setCurrents = new List <TextBox> {
                txtSetCurr1, txtSetCurr2, txtSetCurr3,
                txtSetCurr4, txtSetCurr5, txtSetCurr6, txtSetCurr7, txtSetCurr8, txtSetCurr9,
                txtSetCurr10, txtSetCurr11, txtSetCurr12
            };
            _tempSensors = new List <TextBox> {
                txtTempSensSample1, txtTempSensSample2,
                txtTempSensSample3, txtTempSensSample4, txtTempSensSample5, txtTempSensSample6,
                txtTempSensSample7, txtTempSensSample8, txtTempSensSample9,
                txtTempSensSample10, txtTempSensSample11, txtTempSensSample12
            };
            //_tempLabels = new List<Label> { labelTemp1, labelTemp2,
            //labelTemp3,labelTemp4,labelTemp5,labelTemp6,
            //labelTemp7,labelTemp8,labelTemp9,labelTemp10,
            //labelTemp11,labelTemp12, labelTemp13, labelTemp14, labelTemp15, labelTemp16};
            //_smokeLabels = new List<Label> { labelSmoke1, labelSmoke2,
            //labelSmoke3,labelSmoke4,labelSmoke5,labelSmoke6,
            //labelSmoke7,labelSmoke8};
            _voltageLabels = new List <Label> {
                lblVoltage1, lblVoltage2, lblVoltage3,
                lblVoltage4, lblVoltage5, lblVoltage6, lblVoltage7, lblVoltage8, lblVoltage9,
                lblVoltage10, lblVoltage11, lblVoltage12
            };
            _currentLabels = new List <Label> {
                lblCurrent1, lblCurrent2, lblCurrent3,
                lblCurrent4, lblCurrent5, lblCurrent6, lblCurrent7, lblCurrent8, lblCurrent9,
                lblCurrent10, lblCurrent11, lblCurrent12
            };
            _cycleLabels = new List <Label> {
                lblCycle1, lblCycle2, lblCycle3,
                lblCycle4, lblCycle5, lblCycle6, lblCycle7, lblCycle8, lblCycle9,
                lblCycle10, lblCycle11, lblCycle12
            };
            _connectedLabels = new List <Label> {
                lblPSStatus1, lblPSStatus2, lblPSStatus3,
                lblPSStatus4, lblPSStatus5, lblPSStatus6, lblPSStatus7, lblPSStatus8, lblPSStatus9,
                lblPSStatus10, lblPSStatus11, lblPSStatus12
            };
            _loadButtons = new List <Button> {
                btnLoad1, btnLoad2, btnLoad3, btnLoad4,
                btnLoad5, btnLoad6, btnLoad7, btnLoad8, btnLoad9, btnLoad10, btnLoad11, btnLoad12
            };
            //_newButtons = new List<Button> { btnNew1, btnNew2, btnNew3 , btnNew4 ,
            //btnNew5,btnNew6,btnNew7,btnNew8,btnNew9,btnNew10,btnNew11,btnNew12};
            _voc = new List <TextBox> {
                txtVoc1, txtVoc2, txtVoc3, txtVoc4, txtVoc5,
                txtVoc6, txtVoc7, txtVoc8, txtVoc9, txtVoc10, txtVoc11, txtVoc12
            };
            _numCells = new List <TextBox> {
                txtNumCells1, txtNumCells2, txtNumCells3,
                txtNumCells4, txtNumCells5, txtNumCells6, txtNumCells7, txtNumCells8, txtNumCells9
                , txtNumCells10, txtNumCells11, txtNumCells12
            };

            // reload default settings to GUI
            txtOperator.Text        = Properties.Settings.Default.Operator;
            txtBiasOn.Text          = Properties.Settings.Default.BiasON;
            txtBiasOff.Text         = Properties.Settings.Default.BiasOFF;
            txtCurrOnTempSet.Text   = Properties.Settings.Default.BiasONTempSet;
            txtCurrOffTempSet.Text  = Properties.Settings.Default.BiasOFFTempSet;
            txtOverTempSet.Text     = Properties.Settings.Default.OverTempSet;
            txtSmokeOverSet.Text    = Properties.Settings.Default.OverSmokeSet;
            textBoxOverVoltage.Text = Properties.Settings.Default.OverVoltage;
            txtPauseFans.Text       = Properties.Settings.Default.PauseFanTime;
            if (Properties.Settings.Default.CheckBoxes != null)
            {
                var iii  = 0;
                var chks = Properties.Settings.Default.CheckBoxes;
                foreach (var chk in _checkBoxes)
                {
                    chk.Checked = chks[iii];
                    iii++;
                }
            }
            else
            {
                Properties.Settings.Default.CheckBoxes = new List <bool> {
                    false, false, false, false, false, false, false, false, false, false, false, false
                };
            }
            if (Properties.Settings.Default.ActiveTemps != null)
            {
                var temps = chkTemp.Items;
                var ii    = 0;
                foreach (var temp in Properties.Settings.Default.ActiveTemps)
                {
                    chkTemp.SetItemChecked(temps.IndexOf(temps[ii]), temp);
                    ii++;
                }
            }
            else
            {
                Properties.Settings.Default.ActiveTemps = new List <bool> {
                    false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false
                };
            }
            if (Properties.Settings.Default.ActiveSmokes != null)
            {
                var smokes = chkSmoke.Items;
                var ii     = 0;
                foreach (var smoke in Properties.Settings.Default.ActiveSmokes)
                {
                    chkSmoke.SetItemChecked(smokes.IndexOf(smokes[ii]), smoke);
                    ii++;
                }
            }
            else
            {
                Properties.Settings.Default.ActiveSmokes = new List <bool> {
                    false, false, false, false, false, false, false, false
                };
            }
            if (Properties.Settings.Default.Samples == null)
            {
                Properties.Settings.Default.Samples = new List <string> {
                    null, null, null, null, null, null, null, null, null, null, null, null
                };
                btnLoadSamples.Enabled = false;
            }
            Properties.Settings.Default.Save();

            // set TDK rows to disabled until the connnection is good
            EnableTDKRows();

            // initialize TDK objects
            _TDKS = new List <TDK> {
            };
            for (int j = 1; j < 13; j++)
            {
                _TDKS.Add(new TDK("0" + j, j));
            }

            // initialize heartbeatpacket before arduino declarations
            string tempBin = "";

            foreach (object chk in chkTemp.Items)
            {
                tempBin += GetBinary(chkTemp.GetItemChecked(chkTemp.Items.IndexOf(chk)));
            }
            string smokeBin = "";

            foreach (object chk in chkSmoke.Items)
            {
                smokeBin += GetBinary(chkTemp.GetItemChecked(chkTemp.Items.IndexOf(chk)));
            }
            _heartBeatPacket = new TransmitPacket(txtOverTempSet.Text, txtSmokeOverSet.Text,
                                                  txtCurrOnTempSet.Text, txtCurrOffTempSet.Text, "0", "0", tempBin, smokeBin, "0");

            // initialize temp/smoke graphs
            chartTemp.ChartAreas["ChartArea1"].AxisY.Maximum = double.Parse(txtOverTempSet.Text) + 30;
            chartTemp.ChartAreas["ChartArea1"].AxisY.StripLines.Clear();
            StripLine stripline = new StripLine();

            stripline.Interval       = 0;
            stripline.IntervalOffset = double.Parse(txtOverTempSet.Text);
            stripline.StripWidth     = 3;
            stripline.BackColor      = Color.Red;
            chartTemp.ChartAreas["ChartArea1"].AxisY.StripLines.Add(stripline);
            var i = 1;

            foreach (object chk in chkTemp.Items)
            {
                if (chkTemp.GetItemChecked(chkTemp.Items.IndexOf(chk)))
                {
                    var y = 25;
                    chartTemp.Series["Temp"].Points.AddXY(i, y);
                    i++;
                }
            }
            chartSmoke.ChartAreas["ChartArea1"].AxisY.Maximum = double.Parse(txtSmokeOverSet.Text) + 1;
            chartSmoke.ChartAreas["ChartArea1"].AxisY.StripLines.Clear();
            stripline                = new StripLine();
            stripline.Interval       = 0;
            stripline.IntervalOffset = double.Parse(txtSmokeOverSet.Text);
            stripline.StripWidth     = 3;
            stripline.BackColor      = Color.Red;
            chartSmoke.ChartAreas["ChartArea1"].AxisY.StripLines.Add(stripline);
            i = 1;
            foreach (object chk in chkSmoke.Items)
            {
                if (chkSmoke.GetItemChecked(chkSmoke.Items.IndexOf(chk)))
                {
                    var y = 25;
                    chartSmoke.Series["Smoke Level"].Points.AddXY(i, y);
                    i++;
                }
            }

            // wait until arduino is connected to start connecting TDKs
            //#if !DEBUG
            //while (!Connected) { }
            Thread.Sleep(6000);
            //#endif
            _arduinoWorker.ReportProgress(1);
            _connectionWorker.RunWorkerAsync();
            U.Logger.WriteLine($"Checking TDK connections");
            btnStart.Enabled           = false;
            btnCheckConnection.Enabled = false;

#if DEBUG
            var timer = new System.Timers.Timer();
            timer.Elapsed += OnTimedEvent;
            timer.Interval = 1000;
            timer.Start();
#endif
        }
Esempio n. 4
0
        private void UpdateUi(object sender, ProgressChangedEventArgs e)
        {
            try {
                // update TDK readings during Cycling
                if (e.ProgressPercentage == 5)
                {
                    var args = _cycling._args;
                    if (args.Closing)
                    {
                        labelCount.Text    = $@"00:00";
                        lblBiasStatus.Text = _cycling.BIASON ? "BIAS ON" : "BIAS OFF";
                    }
                    else
                    {
                        var ts = (args.CycleTime - DateTime.Now);
                        labelCount.Text    = $@"{ts.Minutes:D2}:{ts.Seconds:D2}";
                        lblBiasStatus.Text = _cycling.BIASON ? "BIAS ON" : "BIAS OFF";
                    }
                    labelOverVoltage.BackColor = args.OverVoltage ? Color.Red : Color.Empty;
                    //labelTempAlarm.BackColor = args.OverTemp ? Color.Red : Color.Empty;
                    //labelSmokeAlarm.BackColor = args.OverSmoke ? Color.Red : Color.Empty;
                    _voltageLabels[args.Port - 1].Text = args.Volt;
                    _currentLabels[args.Port - 1].Text = args.Current;
                    _cycleLabels[args.Port - 1].Text   = args.Cycle;
                    return;
                }
                // re-enable GUI buttons
                else if (e.ProgressPercentage == 1)
                {
                    EnableTDKRows();
                    btnStart.Enabled           = true;
                    chkTemp.Enabled            = true;
                    chkSmoke.Enabled           = true;
                    btnCheckConnection.Enabled = true;
                    btnLoadSamples.Enabled     = true;
                    btnClearSamples.Enabled    = true;
                    buttonClearAlarms.Enabled  = true;
                    return;
                }
                // update temp/smoke/alarm readings
                else if (e.ProgressPercentage == 2)
                {
                    var ardArgs = _arduino._recievedPacket;

                    var i = 0;
                    chartTemp.ChartAreas["ChartArea1"].AxisY.Maximum = double.Parse(txtOverTempSet.Text) + double.Parse(txtOverTempSet.Text) / 10;
                    chartTemp.ChartAreas["ChartArea1"].AxisY.StripLines.Clear();
                    StripLine stripline = new StripLine();
                    stripline.Interval       = 0;
                    stripline.IntervalOffset = double.Parse(txtOverTempSet.Text);
                    stripline.StripWidth     = stripline.IntervalOffset / 70;
                    stripline.BackColor      = Color.Red;
                    chartTemp.ChartAreas["ChartArea1"].AxisY.StripLines.Add(stripline);
                    chartTemp.Series["Temp"].Points.Clear();
                    foreach (object chk in chkTemp.Items)
                    {
                        if (chkTemp.GetItemChecked(chkTemp.Items.IndexOf(chk)))
                        {
                            var y = ardArgs.TempList[i];
                            chartTemp.Series["Temp"].Points.AddXY(chkTemp.Items.IndexOf(chk) + 1, y);
                            i++;
                        }
                    }
                    i = 0;
                    chartSmoke.ChartAreas["ChartArea1"].AxisY.Maximum = double.Parse(txtSmokeOverSet.Text) + double.Parse(txtSmokeOverSet.Text) / 10;
                    chartSmoke.ChartAreas["ChartArea1"].AxisY.StripLines.Clear();
                    stripline                = new StripLine();
                    stripline.Interval       = 0;
                    stripline.IntervalOffset = double.Parse(txtSmokeOverSet.Text);
                    stripline.StripWidth     = stripline.IntervalOffset / 70;
                    stripline.BackColor      = Color.Red;
                    chartSmoke.ChartAreas["ChartArea1"].AxisY.StripLines.Add(stripline);
                    chartSmoke.Series["Smoke Level"].Points.Clear();
                    foreach (object chk in chkSmoke.Items)
                    {
                        if (chkSmoke.GetItemChecked(chkSmoke.Items.IndexOf(chk)))
                        {
                            //var y = ardArgs.SmokeList[i];
                            var y = _smokeLevel[i];
                            chartSmoke.Series["Smoke Level"].Points.AddXY(chkSmoke.Items.IndexOf(chk) + 1, y);
                            i++;
                        }
                    }
                }
                // send event to arduino thread to update serial transmit packet
                else if (e.ProgressPercentage == 3)
                {
                    string tempBin = "";
                    foreach (object chk in chkTemp.Items)
                    {
                        tempBin += GetBinary(chkTemp.GetItemChecked(chkTemp.Items.IndexOf(chk)));
                    }
                    string smokeBin = "";
                    foreach (object chk in chkSmoke.Items)
                    {
                        smokeBin += GetBinary(chkSmoke.GetItemChecked(chkSmoke.Items.IndexOf(chk)));
                    }
                    string biasON = _cycling.BIASON ? "1" : "0";
                    if (_TDKWorker.IsBusy)
                    {
                        Cycling = "1";
                    }
                    _heartBeatPacket = new TransmitPacket(txtOverTempSet.Text, txtSmokeOverSet.Text,
                                                          txtCurrOnTempSet.Text, txtCurrOffTempSet.Text, biasON, "0", tempBin, smokeBin, Cycling);
                    _arduinoWorker.ReportProgress(1);
                }
                // update connection strings from connection worker
                else if (e.ProgressPercentage == 4)
                {
                    var res = (List <string>)e.UserState;
                    int i   = 0;
                    foreach (string str in res)
                    {
                        _connectedLabels[i].Text = str;
                        i++;
                    }
                    EnableTDKRows();
                    btnCheckConnection.Enabled = true;
                    btnStart.Enabled           = true;
                }
                // update smoke/temp charts TESTING
                else if (e.ProgressPercentage == 6)
                {
                    chartTemp.ChartAreas["ChartArea1"].AxisY.Maximum = double.Parse(txtOverTempSet.Text) + double.Parse(txtOverTempSet.Text) / 10;
                    chartTemp.ChartAreas["ChartArea1"].AxisY.StripLines.Clear();
                    StripLine stripline = new StripLine();
                    stripline.Interval       = 0;
                    stripline.IntervalOffset = double.Parse(txtOverTempSet.Text);
                    stripline.StripWidth     = stripline.IntervalOffset / 70;
                    stripline.BackColor      = Color.Red;
                    chartTemp.ChartAreas["ChartArea1"].AxisY.StripLines.Add(stripline);
                    var i = 1;
                    chartTemp.Series["Temp"].Points.Clear();
                    foreach (object chk in chkTemp.Items)
                    {
                        if (chkTemp.GetItemChecked(chkTemp.Items.IndexOf(chk)))
                        {
                            chartTemp.Series["Temp"].Points.AddXY(chkTemp.Items.IndexOf(chk) + 1, yy);
                            i++;
                        }
                    }
                    chartSmoke.ChartAreas["ChartArea1"].AxisY.Maximum = double.Parse(txtSmokeOverSet.Text) + double.Parse(txtSmokeOverSet.Text) / 10;
                    chartSmoke.ChartAreas["ChartArea1"].AxisY.StripLines.Clear();
                    stripline                = new StripLine();
                    stripline.Interval       = 0;
                    stripline.IntervalOffset = double.Parse(txtSmokeOverSet.Text);
                    stripline.StripWidth     = stripline.IntervalOffset / 70;
                    stripline.BackColor      = Color.Red;
                    chartSmoke.ChartAreas["ChartArea1"].AxisY.StripLines.Add(stripline);
                    chartSmoke.Series["Smoke Level"].Points.Clear();
                    i = 1;
                    foreach (object chk in chkSmoke.Items)
                    {
                        if (chkSmoke.GetItemChecked(chkSmoke.Items.IndexOf(chk)))
                        {
                            chartSmoke.Series["Smoke Level"].Points.AddXY(chkSmoke.Items.IndexOf(chk) + 1, yy);
                            i++;
                        }
                    }
                }
            }
            catch { }
        }
Esempio n. 5
0
 public ArduinoMachine()
 {
     _transmitPacket = new TransmitPacket("200", "200", "85", "25", "0", "0", "0000000000000000", "00000000");
 }
Esempio n. 6
0
 public void UpdateTransmit(TransmitPacket t)
 {
     _transmitPacket = t;
 }