Beispiel #1
0
        void spManager_NewSerialDataRecieved(object sender, SerialDataEventArgs e)
        {
            if (this.InvokeRequired)
            {
                // Using this.Invoke causes deadlock when closing serial port, and BeginInvoke is good practice anyway.
                this.BeginInvoke(new EventHandler<SerialDataEventArgs>(spManager_NewSerialDataRecieved), new object[] { sender, e });
                return;
            }

            int maxTextLength = 1000; // maximum text length in text box
            if (readings.TextLength > maxTextLength)
                readings.Text = readings.Text.Remove(0, readings.TextLength - maxTextLength);

            string str = Encoding.ASCII.GetString(e.Data);

            try
            {
                interpreter.ParseInput(str);
            }
            catch (Exception ex)
            {
                sw3.WriteLine("Exception Message: " + ex.Message);
                sw3.WriteLine("Exception Source: " + ex.Source);
                sw3.WriteLine("Exception InnerException: " + ex.InnerException);
                sw3.WriteLine("Exception TargetSite: " + ex.TargetSite);
                sw3.WriteLine("#######################################");
            }

            if (sensorReading != interpreter.CurrentReading)
            {
                sensorReading = interpreter.CurrentReading;
                UpdateManometers();
                readings.AppendText("\r\n" + str);
                readings.ScrollToCaret();

                string s = string.Format("TEMP:{0} | HUM:{1} | CO:{2} | CO2:{3}",
                sensorReading.Temperature, sensorReading.Humidity, sensorReading.COLevel, sensorReading.CO2Level);

                formattedReadings.AppendText("\r\n" + s);
                formattedReadings.ScrollToCaret();

                sw2.WriteLine(s);

            }

            sw1.WriteLine(str);
        }
Beispiel #2
0
        private void CO2(string buffer)
        {
            state = State.CO2;

            bool done = ParseFloat(buffer);

            if (done)
            {
                fSt = FloatState.Integer;
                co2Val = val;
                val = 0f;
                pow = 1;

                current = new Reading(temp, hum, coVal, co2Val);
                pos++;
                S(buffer);
            }
        }