Beispiel #1
0
        private void buttonStartTimer_Click(object sender, EventArgs e)
        {/*
          * DialogResult dialogResult = MessageBox.Show("Before starting always check that the weight scale container is not full of liquid", "", MessageBoxButtons.OKCancel);
          * if (dialogResult == DialogResult.Cancel)
          * {
          * return;
          * }*/
            try
            {
                Convert.ToDouble(textBoxHeight.Text);
            }
            catch (Exception)
            {
                MessageBox.Show("The value for Liquid Column (Head Difference) must be a valid number!");
                return;
            }

            buttonStartTimer.Enabled = false;
            if (!checkBoxSaveData.Checked)
            {
                DialogResult dialogResult = MessageBox.Show("Are you sure you don't want to save the data? (No report will be created)", "You didn't check the Save Data checkbox", MessageBoxButtons.OKCancel);
                if (dialogResult == DialogResult.Cancel)
                {
                    buttonStartTimer.Enabled = true;
                    return;
                }
            }



            if (checkBoxSaveData.Checked)
            {
                if ((textBoxHeight.Text == "") || (textBoxViscosity.Text == "") || (textBoxDiameter.Text == "") || (textBoxThickness.Text == ""))
                {
                    MessageBox.Show("You must enter a value for all fields");
                    return;
                }

                if (File.Exists(textBoxPath.Text))
                {
                    DialogResult result = MessageBox.Show("This data file already exists. Do you want to overwrite it?", "Overwrite data file?", MessageBoxButtons.YesNo);
                    if (result == System.Windows.Forms.DialogResult.No)
                    {
                        buttonStartTimer.Enabled = true;
                        return;
                    }
                }

                settings.sampleThickness = textBoxThickness.Text;
                settings.diameter        = textBoxDiameter.Text;
                settings.viscosity       = textBoxViscosity.Text;
                if (radioButton1.Checked)
                {
                    settings.upperSelected  = true;
                    settings.middleSelected = false;
                    settings.lowerSelected  = false;
                    settings.upperHeight    = textBoxHeight.Text;
                }
                else if (radioButton2.Checked)
                {
                    settings.upperSelected  = false;
                    settings.middleSelected = true;
                    settings.lowerSelected  = false;
                    settings.middleHeight   = textBoxHeight.Text;
                }
                else if (radioButton3.Checked)
                {
                    settings.upperSelected  = false;
                    settings.middleSelected = false;
                    settings.lowerSelected  = true;
                    settings.lowerHeight    = textBoxHeight.Text;
                }
                settings.height = textBoxHeight.Text;
                settings.Save();

                settings.dataPath = textBoxPath.Text;
                settings.Save();

                //create directory
                try
                {
                    Directory.CreateDirectory((Directory.GetParent(textBoxPath.Text)).ToString());
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                CommonClass.writeHeader();
            }

            /*
             * //close valve 2
             *
             * COMMS.openValve2(); //sample valve
             * Thread.Sleep(800);
             * COMMS.closeValve3(); //weight valve
             * Thread.Sleep(800);
             * COMMS.openValve1(); //top reservoir valve
             */

            //open valve 2:
            if (checkBoxV2OnStart.Checked)
            {
                //COMMS.openValve2();

                /*// new atira
                 * openValve2 = true;
                 */
            }

            stopwatch.Reset();
            stopwatch.Start();

            /*
             * scaleReading = COMMS.ReadScale().ToString(); //reads the first weight value which will be first data point.
             * originalWeight = Convert.ToDouble(scaleReading);
             * netWeight();*/

            /*
             * while (true) //get a first reading
             * {
             * scaleReading = COMMS.ReadScaleAWS();
             * if (scaleReading != "" && !scaleReading.Contains("M") && scaleReading.Length > 2)
             * {
             *  scaleReading = scaleReading.Substring(2, scaleReading.Length - 3);
             *  originalWeight = Convert.ToDouble(scaleReading);
             *  netWeight();
             *  break;
             * }
             * }*/
            originalWeight = Convert.ToDouble(lastValidScaleReading);


            if (backgroundWorkerElapsedTime.IsBusy != true)
            {
                backgroundWorkerElapsedTime.RunWorkerAsync();
            }

            testRunning = true;
        }
Beispiel #2
0
        private void backgroundWorkerReadScale_DoWork(object sender, DoWorkEventArgs e)
        {
            while (true)
            {
                if (testStopped)
                {
                    Debug.WriteLine("RETURN; hit");
                    Debug.WriteLine("RETURN; hit");
                    Debug.WriteLine("RETURN; hit");
                    return;
                }
                if (openValve1)
                {
                    COMMS.openValve4();
                    openValve1 = false;
                }
                if (closeValve1)
                {
                    COMMS.closeValve4();
                    closeValve1 = false;
                }
                if (openValve2)
                {
                    COMMS.openValve2();
                    openValve2 = false;
                }
                if (openValve3)
                {
                    COMMS.openValve3();
                    openValve3 = false;
                }

                if (closeValve2)
                {
                    COMMS.closeValve2();
                    //MessageBox.Show("Test");
                    closeValve2 = false;
                }
                if (closeValve3)
                {
                    COMMS.closeValve3();
                    closeValve3 = false;
                }

                scaleReading = COMMS.ReadScaleAWS();
                if (scaleReading.Length > 4)
                {
                    //lastValidScaleReading = filterReading(scaleReading);
                    lastValidScaleReading = CommonClass.filterRegex(scaleReading);
                    backgroundWorkerReadScale.ReportProgress(0);
                }

                /*
                 * scaleReading = COMMS.ReadScaleAWS();
                 * //if (scaleReading != "" && !scaleReading.Contains("M") && scaleReading.Length > 2)
                 * if (scaleReading != "" && scaleReading.Length > 4)
                 * {
                 * splitReceived = scaleReading.Split(new string[] { "g" }, StringSplitOptions.None);
                 * splitReceived = splitReceived[0].Split(new string[] { ":" }, StringSplitOptions.None);
                 * scaleReading = splitReceived[1];
                 * //scaleReading = scaleReading.Substring(2, scaleReading.Length - 3);
                 * if (scaleReading != "")
                 * {
                 *  lastValidScaleReading = scaleReading;
                 * }
                 *
                 *
                 * backgroundWorkerReadScale.ReportProgress(0);
                 * if ((backgroundWorkerReadScale.CancellationPending == true))
                 * {
                 *  Debug.WriteLine("e.Cancel ; hit");
                 *  Debug.WriteLine("e.Cancel ; hit");
                 *  Debug.WriteLine("e.Cancel ; hit");
                 *  e.Cancel = true;
                 *  break;
                 * }
                 * }
                 */

                Thread.Sleep(150);
            }
        }
Beispiel #3
0
        public void SaveDataTableToFile()
        {
            writeHeader();
            SR = new StreamWriter(filePath, true);
            //option 1: first write the data from the last round

            /*foreach (DataRow row in tableArray[round - 2].Rows)
             * {
             * SR.WriteLine("{0,10}\t{1,10}", row.Field<string>(0), row.Field<string>(1));
             * lastw = row.Field<string>(1);
             * lastT = row.Field<string>(0);
             * }*/

            //option 2: write the average data from all the rounds
            int rowcount = 0;

            try
            {
                foreach (DataRow row in tableArray[round - 2].Rows)
                {
                    double sum     = 0;
                    double average = 0;

                    for (int i = 0; i < (round - 1); i++)
                    {
                        sum = sum + Convert.ToDouble(tableArray[i].Rows[rowcount][1]);
                    }
                    average = sum / (round - 1);
                    rowcount++;
                    SR.WriteLine("{0,10}\t{1,10}", row.Field <string>(0), average.ToString("0"));
                    lastw = average.ToString("0");
                    lastT = row.Field <string>(0);
                }
            }
            catch (Exception)
            {
                Debug.WriteLine("ERROR IN LOOPONG THROUGH tableArray");
            }


            //

            SR.WriteLine("");
            SR.WriteLine("***************************");
            SR.WriteLine("");
            //
            SR.WriteLine("Total Weight = " + lastw + " g");
            SR.WriteLine("Total Time = " + lastT + " Secs");
            //SR.WriteLine("Flow Velocity = " + (weight / (Convert.ToDouble(settings.area) * time)).ToString("#0.000") + " cm/s");
            vel = (Convert.ToDouble(lastw) / (Convert.ToDouble(settings.area) * Convert.ToDouble(lastT))).ToString("#0.000");
            SR.WriteLine("Flow Velocity = " + vel + " cm/s");
            SR.WriteLine("");
            SR.WriteLine("***************************");
            SR.WriteLine("");
            CommonClass.addVelToLast5(vel);
            //
            if (settings.maxRepetitions > 1)
            {
                for (int i = 0; i < round - 1; i++)
                {
                    SR.WriteLine("Round " + ((i + 1).ToString()));
                    foreach (DataRow row in tableArray[i].Rows)
                    {
                        SR.WriteLine("{0,10}\t{1,10}", row.Field <string>(0), row.Field <string>(1));
                    }
                    SR.WriteLine("");
                }
                SR.WriteLine("***************************");
                SR.WriteLine("");
                int k = 0;
                foreach (DataRow row in finalWeights.Rows)
                {
                    k++;
                    SR.WriteLine("{0,10}\t{1,10}", "Weight Round " + k.ToString(), row.Field <string>(0));
                }
                SR.WriteLine("{0,10}\t{1,10}", "Average Weight ", average.ToString("0"));
            }
            SR.Close();
        }