コード例 #1
0
ファイル: WS2300.cs プロジェクト: faina09/WS2300
        private void BtnRead_Click(object sender, EventArgs e)
        {
            double ret;
            int    tempint;

            string[] directions = new string[] { "N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE",
                                                 "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW" };
            short[] winddir = new short[6];
            try
            {
                /* READ TEMPERATURE INDOOR */
                ret = ws2300.temperature_indoor(config.temperature_conv);
                Display("TEMP in=" + ret.ToString());
                /* READ TEMPERATURE OUTDOOR */
                ret = ws2300.temperature_outdoor(config.temperature_conv);
                Display("TEMP out=" + ret.ToString());
                /* READ DEWPOINT */
                ret = ws2300.dewpoint(config.temperature_conv);
                Display("Dew point=" + ret.ToString());
                /* READ RELATIVE HUMIDITY INDOOR */
                ret = ws2300.humidity_indoor();
                Display("HUM in=" + ret.ToString());
                /* READ RELATIVE HUMIDITY OUTDOOR */
                ret = ws2300.humidity_outdoor();
                Display("HUM out=" + ret.ToString());
                /* READ WIND SPEED AND DIRECTION */
                tempint    = -1;
                winddir[0] = 0xFFF;
                ret        = ws2300.wind_all(config.wind_speed_conv_factor, ref tempint, ref winddir);
                Display("Wind=" + ret.ToString() + " dir:" + winddir[0].ToString() + "° " + directions[tempint]);
                //sprintf(logline, "%s%.1f %s ", logline, winddir[0], directions[tempint]);
                /* READ WINDCHILL */
                ret = ws2300.windchill(config.temperature_conv);
                Display("Windchill=" + ret.ToString());
                /* READ RAIN 1H */
                ret = ws2300.rain_1h(config.rain_conv_factor);
                Display("RAIN 1h=" + ret.ToString());
                /* READ RAIN 24H */
                ret = ws2300.rain_24h(config.rain_conv_factor);
                Display("RAIN 24h=" + ret.ToString());
                /* READ RAIN TOTAL */
                ret = ws2300.rain_total(config.rain_conv_factor);
                Display("RAIN tot=" + ret.ToString());
                /* READ RELATIVE PRESSURE */
                ret = ws2300.rel_pressure(config.pressure_conv_factor);
                Display("PRESS rel=" + ret.ToString());
                /* READ TENDENCY AND FORECAST */
                string tendency = "";
                string forecast = "";
                ws2300.tendency_forecast(ref tendency, ref forecast);
                Display("   tendency=" + tendency);
                Display("   forecast=" + forecast);
            }
            catch (Exception ex)
            {
                Display("ERROR: " + ex.Message);
            }
            Display("");
        }
コード例 #2
0
        /// <summary>
        /// Method for ThreadStart delegate
        /// </summary>
        public void RunProcess()
        {
            string[] var;
            string   rVal;
            double   ret;
            int      tempint;

            string[] directions = new string[] { "N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE",
                                                 "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW" };
            short[] winddir = new short[6];

            Thread.CurrentThread.IsBackground = true; //make them a daemon
            try
            {
                var  = m_variables.Split(',');
                rVal = "undef";
                foreach (string s in var)
                {
                    switch (s.Trim().ToUpper())
                    {
                    case "T_IN":
                        rVal = m_ws2300.temperature_indoor(m_config.temperature_conv).ToString("F2");
                        break;

                    case "T_OUT":
                        rVal = m_ws2300.temperature_outdoor(m_config.temperature_conv).ToString("F2");
                        break;

                    case "DEW":
                        rVal = m_ws2300.dewpoint(m_config.temperature_conv).ToString("F2");
                        break;

                    case "H_IN":
                        rVal = m_ws2300.humidity_indoor().ToString();
                        break;

                    case "H_OUT":
                        rVal = m_ws2300.humidity_outdoor().ToString();
                        break;

                    case "WIND":
                        tempint    = -1;
                        winddir[0] = 0xFFF;
                        ret        = m_ws2300.wind_all(m_config.wind_speed_conv_factor, ref tempint, ref winddir);
                        rVal       = "Wind=" + ret.ToString() + " dir:" + winddir[0].ToString() + "° " + directions[tempint];
                        break;

                    case "W_CHILL":
                        rVal = m_ws2300.windchill(m_config.temperature_conv).ToString("F2");
                        break;

                    case "PRESS":
                        rVal = m_ws2300.rel_pressure(m_config.pressure_conv_factor).ToString("F2");
                        break;

                    case "HISTORY":
                        rVal = HistoryRecord();
                        break;
                    }
                    if (rVal != "")
                    {
                        UpdateMessage(rVal, false);
                    }
                }
                UpdateMessage("read ENDED", true);
            }
            catch (Exception ex)
            {
                UpdateMessage("ERROR: " + ex.Message, true);
            }
        }