示例#1
0
        /// <summary>
        /// Gets a List of type Trim with all the sensor trim and enabled values as
        /// properties in each object type Trim.
        /// </summary>
        /// <returns>List of type Trim with each list item having two properties
        /// "Enabled" = bool and "Trim" = double </returns>
        public List <Trim> GetValues()
        {
            numCrunch   pluto    = new numCrunch();
            DataTable   result   = pluto.configLoad();
            List <Trim> procTrim = new List <Trim>();

            try
            {
                int count = result.Rows.Count;
                for (int i = 0; i < 16; i++)
                {
                    Trim temp = new Trim();
                    if (i == 16)
                    {
                        temp.Enabled   = Convert.ToBoolean(result.Rows[i + 1][4]);
                        temp.TrimValue = Convert.ToDouble(result.Rows[i + 1][3].ToString());
                    }
                    else if (i == 17)
                    {
                        temp.Enabled   = Convert.ToBoolean(result.Rows[i - 1][4]);
                        temp.TrimValue = Convert.ToDouble(result.Rows[i - 1][3].ToString());
                    }
                    else if (i == 18)
                    {
                        temp.Enabled   = Convert.ToBoolean(result.Rows[i + 1][4]);
                        temp.TrimValue = Convert.ToDouble(result.Rows[i + 1][3].ToString());
                    }
                    else if (i == 19)
                    {
                        temp.Enabled   = Convert.ToBoolean(result.Rows[i - 1][4]);
                        temp.TrimValue = Convert.ToDouble(result.Rows[i - 1][3].ToString());
                    }
                    else if (i == 20)
                    {
                        temp.Enabled   = Convert.ToBoolean(result.Rows[i + 1][4]);
                        temp.TrimValue = Convert.ToDouble(result.Rows[i + 1][3].ToString());
                    }
                    else if (i == 21)
                    {
                        temp.Enabled   = Convert.ToBoolean(result.Rows[i - 1][4]);
                        temp.TrimValue = Convert.ToDouble(result.Rows[i - 1][3].ToString());
                    }
                    else if (i == 22)
                    {
                        temp.Enabled   = Convert.ToBoolean(result.Rows[i + 1][4]);
                        temp.TrimValue = Convert.ToDouble(result.Rows[i + 1][3].ToString());
                    }
                    else if (i == 23)
                    {
                        temp.Enabled   = Convert.ToBoolean(result.Rows[i - 1][4]);
                        temp.TrimValue = Convert.ToDouble(result.Rows[i - 1][3].ToString());
                    }
                    else
                    {
                        temp.Enabled   = Convert.ToBoolean(result.Rows[i][4]);
                        temp.TrimValue = Convert.ToDouble(result.Rows[i][3].ToString());
                    }
                    procTrim.Add(temp);
                }
                return(procTrim);
            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show("Failed to get Trim Values and Enables \r \n"
                                                     + "Here's Why.... \r \n" + e.ToString());
                return(null);
            }
        }
示例#2
0
        // This method takes the receieved byte[] and determines which processing method to use based on the second element in the received byte[]
        private void process(byte[] rxBuffer)
        {
            TempHumidityProcessing arrange = new TempHumidityProcessing();

            foreach (byte a in rxBuffer)
            {
                rxData.Add(a);
            }
            byte[] tempArray = new byte[rxData.Count];
            try
            {
                tempArray = (byte[])rxData.ToArray(typeof(byte));
            }
            catch (IndexOutOfRangeException e)
            {
                bool bReturnLog = false;
                ErrorLog.LogFilePath = "C:\\Data\\ErrorLogFile.txt";
                //false for writing log entry to customized text file
                bReturnLog = ErrorLog.ErrorRoutine(false, e);

                if (false == bReturnLog)
                {
                    MessageBox.Show("Unable to write a log");
                }
            }

            // Checking to see if rxdata is for temp sensors
            if (tempArray[1] == 0x10 && tempArray.Length == 36)
            {
                if (tempArray[35] == 0)
                {
                    double[] temperatureArray = arrange.ArrangeTemps(tempArray);
                    temperatureArray = arrange.ProcTemps(temperatureArray);
                    fillTemps(temperatureArray);
                }
                rxData.Clear();
            }
            // checking to see if rxdata is for Humidity/temperature sensors
            if (tempArray[1] == 0x20 && tempArray.Length == 20)
            {
                if (tempArray[19] == 0)
                {
                    Trim        trim = new Trim();
                    List <Trim> list = new List <Trim>();
                    list = trim.ReturnValues();
                    double[]          humidArray = arrange.ArrangeHumids(tempArray);
                    TempHumDew        hum1       = new TempHumDew(humidArray[1], humidArray[0], fillit.Rows[32][1].ToString(), list[0].TrimValue, list[0].Enabled);
                    TempHumDew        hum2       = new TempHumDew(humidArray[3], humidArray[2], fillit.Rows[33][1].ToString(), list[2].TrimValue, list[2].Enabled);
                    TempHumDew        hum3       = new TempHumDew(humidArray[5], humidArray[4], fillit.Rows[34][1].ToString(), list[4].TrimValue, list[4].Enabled);
                    TempHumDew        hum4       = new TempHumDew(humidArray[7], humidArray[6], fillit.Rows[35][1].ToString(), list[6].TrimValue, list[6].Enabled);
                    List <TempHumDew> humDew     = new List <TempHumDew>();
                    humDew.Add(hum1);
                    humDew.Add(hum2);
                    humDew.Add(hum3);
                    humDew.Add(hum4);
                    fillHumps(humDew);
                    lcd.ExtractStrings(humDew);
                    procdValues = trim.ProcessTrim(trim.GetValues(), procdValues);
                    FillAll(procdValues);
                    label33.Text = "LCD Present = " + lcd.IsOpen.ToString();
                }
                rxData.Clear();
            }

            // checking to see if rxdata is for aux inputs
            if (tempArray[1] == 0x30 && tempArray.Length == 20)
            {
                if (tempArray[19] == 0)
                {
                    double[] auxArray = arrange.ArrangeAuxs(tempArray);
                    auxArray = arrange.ProcAuxs(auxArray);
                    fillAuxs(auxArray);
                }
                rxData.Clear();
            }

            // checking to see if information is for relays
            if (tempArray[1] == 0x50 && tempArray.Length == 7)
            {
                if (tempArray[6] == 0)
                {
                    DisplayRelayStatus(tempArray[2]);
                }
                rxData.Clear();
            }
        }