예제 #1
0
파일: Program.cs 프로젝트: speedyjeff/tides
 private static void List()
 {
     // display all the vendor and product ids
     foreach (var id in AcuriteStation.All())
     {
         Console.WriteLine($"VendorId: {id.VendorId} (0x{id.VendorId:x}), ProductId: {id.ProductId} (0x{id.ProductId:x})");
     }
 }
예제 #2
0
파일: Program.cs 프로젝트: speedyjeff/tides
        //
        // Common
        //
        private void PollStation(Options options)
        {
            // setup
            var station  = new AcuriteStation();
            var combined = new AcuriteData();

            // poll the station until asked to stop
            var failCount = 0;

            while (true)
            {
                // check if the poll timeout has occured (in which case, skip this station read)
                if (LastNetQuery.ElapsedMilliseconds < options.SleepPolling)
                {
                    // read data
                    AcuriteData current;
                    if (options.VendorId.HasValue && options.ProductId.HasValue)
                    {
                        current = station.Read(options.VendorId.Value, options.ProductId.Value);
                    }
                    else
                    {
                        current = station.Read();
                    }

                    // send if there is data
                    if (!current.HasValue())
                    {
                        failCount++;
                        Console.WriteLine($"{DateTime.Now:o}: failed to get a station reading");
                        if (failCount >= options.MaxPollFailures)
                        {
                            throw new Exception($"Failed to get station data {failCount} in a row");
                        }
                    }
                    else
                    {
                        // reset fail count (if set)
                        failCount = 0;

                        // combine the data into a view of the latest
                        combined = combined + current;

                        // display
                        var data = combined;
                        if (options.RawData)
                        {
                            data = current;
                        }
                        Console.WriteLine($"{DateTime.Now:o}:{(options.RawData ? " [raw]" : "")} {data.channel},{data.sensorId},{data.signal},{data.lowBattery},{data.windSpeed},{data.windDirection},{data.rainTotal},{data.outTemperature},{data.outHumidity},{data.pressure},{data.inTemperature},{(data.pressureTrend != null ? data.pressureTrend.Length : 0)},{(data.rainTotalTrend != null ? data.rainTotalTrend.Length : 0)}");

                        // notifiy of data
                        if (OnPolled != null)
                        {
                            OnPolled(data);
                        }
                    }
                }

                System.Threading.Thread.Sleep(options.Interval);
            }
        }