Ejemplo n.º 1
0
        /// <summary>
        /// Raised by the <see cref="MeasurementTimer"/>. Collects data from board.
        /// </summary>
        private void OnMeasurementTimerTickWindows(object state)
        {
            try {
                if (running)
                {
                    double time = KeeperOfTime.ElapsedMilliseconds;

                    var analogPins = Configuration.AnalogPins.Where(o => o.LastValue + o.Interval < time).ToArray();

                    if (analogPins.Length > 0)
                    {
                        analogPins.ToList().ForEach(o => o.LastValue += o.Interval);

                        var query = analogPins.Select(o => o.Number).ToArray();
                        var vals  = ArduinoController.ReadAnalogPin(query);

                        var now = DateTime.Now;

                        for (int i = 0; i < analogPins.Length; i++)
                        {
                            lock (analogPins) {
                                analogPins [i].Value = new DateTimeValue(vals [i], now);
                            }
                        }

                        var analogPinValues      = analogPins.Select(o => o.Value.Value).ToList <double> ();
                        var analogPinValuesNames = analogPins.ToList().Select(o => o.DisplayName).ToList();

                        var MeComValues = Configuration.MeasurementCombinations
                                          .Where(o => !double.IsNaN(o.Value.Value))
                                          .Select(o => o.Value.Value)
                                          .ToList <double> ();
                        var MeComValuesNames = Configuration.MeasurementCombinations
                                               .Where(o => !double.IsNaN(o.Value.Value))
                                               .Select(o => o.DisplayName)
                                               .ToList();

                        var names = analogPinValuesNames;
                        names.AddRange(MeComValuesNames);
                        var values = analogPinValues;
                        values.AddRange(MeComValues);

                        MeasurementCSVLogger.Log(names, values);
                    }
                }
                else
                {
                    System.Threading.Timer t = (System.Threading.Timer)state;
                    t.Dispose();
                }
            } catch (Exception e) {
                ConLogger.Log(e.ToString(), LogLevel.ERROR);
            }
        }