コード例 #1
0
 public void Add(LDRValues newValue)
 {
     allReadings.Add(newValue);
     portNumber   = "";
     minthreshold = 0;
     threshold    = 0;
     fileCount    = 0;
 }
コード例 #2
0
ファイル: Form1.cs プロジェクト: aparnapm/LDR_ControlApp
        /// <summary>
        /// The function sets the minimum maximum and threshold count
        /// </summary>
        public void setValues()
        {
            bunifuGauge1.Value = val;
            LDRValues singleReading = new LDRValues();

            singleReading.IntensityValue = val;
            singleReading.CurrentTime    = elapsedTime;
            sessionend.Text = elapsedTime;
            if (flag == 1)
            {
                if (val < mininumReading)
                {
                    minimum.Text   = val.ToString();
                    mininumReading = val;
                }

                if (val > maximumReading)
                {
                    maximum.Text   = val.ToString();
                    maximumReading = val;
                }
            }
            else
            {
                sessionstart.Visible = true;
                sessionstart.Text    = elapsedTime;
                minimum.Text         = val.ToString();
                minimum.Visible      = true;
                mininumReading       = val;
                maximum.Text         = val.ToString();
                maximum.Visible      = true;
                maximumReading       = val;
                flag = 1;
            }
            try
            {
                if (val > int.Parse(threshold.Text) || val < int.Parse(minthreshold.Text))
                {
                    aboveThresholdCount++;
                    thresholdcount.Text       = aboveThresholdCount.ToString();
                    thresholdcount.Visible    = true;
                    singleReading.AlarmRaised = true;
                    pictureBox1.Image         = Image.FromFile("../../Files/alert.png");
                }
                else
                {
                    pictureBox1.Image         = null;
                    singleReading.AlarmRaised = false;
                }

                /* if((int.Parse(threshold.Text)<= int.Parse(minthreshold.Text))||(int.Parse(threshold.Text)<=0)|| (int.Parse(minthreshold.Text) < 0))
                 * {
                 *   errorLabel.Text = "Enter a valid range";
                 *   isThresholdValuesValid = 1;
                 *
                 * }*/
            }
            catch (Exception)
            {
                errorLabel.Text    = "Invalid entry";
                errorLabel.Visible = true;
                return;
            }

            button7.Enabled = true;
            singleReading.MinimumIntensity = mininumReading;
            singleReading.MaximumIntensity = maximumReading;
            listOfReadings.AllReadings.Add(singleReading);
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: aparnapm/LDR_ControlApp
        /// <summary>
        /// Extracts information from the XML file already generated
        /// </summary>
        /// <param name="fileName"></param>
        private void loadData(string fileName)
        {
            if (clientport.IsOpen)
            {
                clientport.Close();
            }
            Panel.Visible = false;
            displaySettingsPanel.Visible = false;
            string       path           = fileName;
            LDRValues    lastReading    = new LDRValues();
            LDRValueList listOfReadings = new LDRValueList();

            try
            {
                XmlSerializer dataSerializer = new XmlSerializer(typeof(LDRValueList));
                using (StreamReader reader = new StreamReader(path))
                {
                    listOfReadings = (LDRValueList)dataSerializer.Deserialize(reader);
                }
            }
            catch (System.InvalidOperationException)
            {
                errorLabel.Text    = "Please select XML data-file for parsing";
                errorLabel.Visible = true;
                return;
            }
            catch (ArgumentException)
            {
                errorLabel.Text    = "Error:File Not Selected";
                errorLabel.Visible = true;
                return;
            }
            this.dataGridView1.RowPostPaint += new System.Windows.Forms.DataGridViewRowPostPaintEventHandler(this.dataGridView1_RowPostPaint);
            dataGridView1.DataSource         = listOfReadings.AllReadings;
            try
            {
                lastReading       = listOfReadings.AllReadings[listOfReadings.AllReadings.Count - 1];
                sessionstart.Text = listOfReadings.AllReadings[0].CurrentTime;
            }

            catch (ArgumentOutOfRangeException)
            {
                errorLabel.Text    = "Error:No readings were obtained";
                errorLabel.Visible = true;
                return;
            }
            foreach (var series in chart1.Series)
            {
                series.Points.Clear();
            }
            int overThresholdCount = 0;

            try
            {
                foreach (LDRValues singleReading in listOfReadings.AllReadings)
                {
                    chart1.Series[0].Points.AddXY(singleReading.CurrentTime, singleReading.IntensityValue);
                    if (singleReading.AlarmRaised)
                    {
                        overThresholdCount++;
                    }
                }
            }
            catch (ArgumentNullException)
            {
                errorLabel.Text    = "Error:The file contains corrupt values";
                errorLabel.Visible = false;
                return;
            }


            try
            {
                minimum.Text                 = lastReading.MinimumIntensity.ToString();
                maximum.Text                 = lastReading.MaximumIntensity.ToString();
                thresholdcount.Text          = overThresholdCount.ToString();
                displayPort.Text             = listOfReadings.PortNumber.ToString();
                displayMinThreshold.Text     = listOfReadings.Minthreshold.ToString() + "-" + listOfReadings.Threshold.ToString();
                displaySettingsPanel.Visible = true;
            }
            catch (NullReferenceException)
            {
                errorLabel.Text    = "Error:The XML contains missing fields!";
                errorLabel.Visible = true;
                Panel.Visible      = false;
                return;
            }
            generate.Visible     = false;
            manualStatus.Visible = false;
            rightPanel.SetRowSpan(valuePanel, 2);
            valuesPanel2.Visible = false;
            valuePanel.SetRowSpan(dataGridView1, 2);
            bunifuGauge1.Visible       = false;
            dataGridView1.Visible      = true;
            errorLabel.Visible         = false;
            settingsTablePanel.Visible = false;
            rightPanel.Visible         = true;
            Panel.Visible = true;
        }