示例#1
0
        private void DrawDayGraph(double xmin, double xmax, double ymin, double ymax, string day)
        {
            List <DateTime> dateTimeList    = new List <DateTime>();
            List <float>    temperatureList = new List <float>();
            List <float>    humidityList    = new List <float>();

            DatabaseOperations.GetTableData(day, ref dateTimeList, ref temperatureList, ref humidityList);

            List <int> hours = new List <int>();

            foreach (var time in dateTimeList)
            {
                hours.Add(time.Hour);
            }

            int hourDifference = hours.Max() - hours.Min();

            if (hourDifference != 24)
            {
                hourDifference += 1;
            }

            double xstep   = xmax / hourDifference;
            double ystep_t = ymax / Math.Ceiling(temperatureList.Max() / 5);
            double ystep_h = ymax / 10;

            DrawX_Axis_Day(xmin, ymax, hourDifference, xstep, hours.Min());

            DrawY_Axis(xmin, xmax, ymax, temperatureList.Max(), ystep_t, ystep_h);

            //calculate step size
            double hourStep   = xmax / hourDifference;
            double minuteStep = xmax / (hourDifference * 60);
            double secondStep = xmax / (hourDifference * 3600);
            double tempStep   = ymax / (Math.Ceiling(temperatureList.Max() / 5) * 5);
            double humStep    = ymax / 100;

            DrawGraphLine(Brushes.Red, dateTimeList, temperatureList, hours.Min(), hourStep, minuteStep, secondStep, tempStep, ymax, true, DateTime.Now, 0);
            DrawGraphLine(Brushes.Blue, dateTimeList, humidityList, hours.Min(), hourStep, minuteStep, secondStep, humStep, ymax, true, DateTime.Now, 0);

            DrawGraphLineColorNotations(ymax);

            MaxTempHumLbl.Content = Math.Round(temperatureList.Max(), 1) + "°C; " + Math.Round(humidityList.Max(), 1) + "%";
            MinTempHumLbl.Content = Math.Round(temperatureList.Min(), 1) + "°C; " + Math.Round(humidityList.Min(), 1) + "%";
        }
示例#2
0
        public void ReadCallback(IAsyncResult ar)
        {
            String content = String.Empty;

            // Retrieve the state object and the handler socket
            // from the asynchronous state object.
            StateObject state   = (StateObject)ar.AsyncState;
            Socket      handler = state.workSocket;

            // Read data from the client socket.
            int bytesRead = handler.EndReceive(ar);

            if (bytesRead > 0)
            {
                if (ArduinoErrors["ServerComErr"].IsActive)
                {
                    ArduinoErrors["ServerComErr"].IsActive = false;
                }
                _commErrorWatch.Restart();

                // There  might be more data, so store the data received so far.
                state.sb.Append(Encoding.ASCII.GetString(state.buffer, 0, bytesRead));

                // Check for end-of-file tag. If it is not there, read more data.
                content = state.sb.ToString();
                if (content.IndexOf("<") > -1)
                {
                    // All the data has been read from the client.

                    if (content.Contains("&"))
                    {
                        Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
                        {
                            _tempLabel.Content = content.Split('&')[0] + " °C";
                            _humLabel.Content  = content.Split('&')[1].Split('<')[0] + " %";
                        }));

                        float temp;
                        float hum;
                        if (float.TryParse(content.Split('&')[0].Replace('.', ','), out temp) &&
                            float.TryParse(content.Split('&')[1].Split('<')[0].Replace('.', ','), out hum))
                        {
                            ArduinoErrors["DHT_No1Err"].IsActive = false;
                            if (!DatabaseOperations.DatabaseIsInProccess)
                            {
                                if (!DatabaseErrors["DatabaseErr"].IsActive)
                                {
                                    if (!DatabaseOperations.DatabaseError)
                                    {
                                        DatabaseOperations.UpdateTempHumDbDayTable(DateTime.Now, temp, hum);
                                    }
                                    else
                                    {
                                        ArduinoErrors["DatabaseErr"].IsActive = true;
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (!ArduinoErrors["DHT_No1Err"].IsActive)
                            {
                                ArduinoErrors["DHT_No1Err"].IsActive = true;
                            }
                        }
                    }
                    Send(handler, content);
                }
                else
                {
                    // Not all data received. Get more.
                    handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(ReadCallback), state);
                }
            }
        }