Exemple #1
0
        void get_device()
        {
            var l  = new libtemphumidnet.LibTempHumid();
            var ds = l.Devices;

            if (ds.Count > 0)
            {
                d = ds[0];
            }
        }
Exemple #2
0
        private void update()
        {
            if (d == null)
            {
#if !RAND
                label1.Text = "No Device";
                label2.Text = "";
#endif

                if (chk_count-- == 0)
                {
                    get_device();
                    chk_count = chk_interval;
                }

#if !RAND
            }
            else
            {
                var temp  = d.Temperature;
                var humid = d.Humidity;
#else
                if (r == null)
                {
                    r = new Random();
                }
                var temp  = r.NextDouble() * 100.0;
                var humid = r.NextDouble() * 50.0;
#endif

                if (double.IsNaN(temp) || double.IsNaN(humid))
                {
                    d = null;
                }
                else
                {
#if RAND
                    label1.Text = temp.ToString("F2") + " °C (R)";
                    label2.Text = humid.ToString("F2") + " % (R)";
#else
                    label1.Text = temp.ToString("F2") + " °C";
                    label2.Text = humid.ToString("F2") + " %";
#endif
                    if (sw != null)
                    {
                        var dt = System.DateTime.Now;
                        sw.WriteLine(dt.ToString("yyyyMMdd\tHH:mm:ss.fff") + "\t" +
                                     temp.ToString("F2") + "\t" +
                                     humid.ToString("F2"));
                        sw.Flush();
                    }
                }
            }
        }