protected void preload_DoWork(object sender, DoWorkEventArgs e)
        {
            if (_mustStopNow)
            {
                return;
            }

            recordedData = _sensor.get_recordedData(0, 0);

            try
            {
                recordedDataLoadProgress = recordedData.loadMore();
            }
            catch (Exception ex) { LogManager.Log(_hwdName + ": preload more caused an exception " + ex.ToString()); }


            globalDataLoadProgress = recordedDataLoadProgress;
            ((BackgroundWorker)sender).ReportProgress(recordedDataLoadProgress);
            List <YMeasure> measures = recordedData.get_preview();

            previewCurData = new List <pointXY>();


            int startIndex = 0;

            for (int i = startIndex; i < measures.Count; i++)
            {
                double t = measures[i].get_endTimeUTC();
                previewCurData.Add(new pointXY()
                {
                    x = t, y = measures[i].get_averageValue()
                });
            }
        }
Example #2
0
 /**
  * <summary>
  *   Retrieves a <c>YDataSet</c> object holding historical data for this
  *   sensor, for a specified time interval.
  * <para>
  *   The measures will be
  *   retrieved from the data logger, which must have been turned
  *   on at the desired time. See the documentation of the <c>YDataSet</c>
  *   class for information on how to get an overview of the
  *   recorded data, and how to load progressively a large set
  *   of measures from the data logger.
  * </para>
  * <para>
  *   This function only works if the device uses a recent firmware,
  *   as <c>YDataSet</c> objects are not supported by firmwares older than
  *   version 13000.
  * </para>
  * <para>
  * </para>
  * </summary>
  * <param name="startTime">
  *   the start of the desired measure time interval,
  *   as a Unix timestamp, i.e. the number of seconds since
  *   January 1, 1970 UTC. The special value 0 can be used
  *   to include any measure, without initial limit.
  * </param>
  * <param name="endTime">
  *   the end of the desired measure time interval,
  *   as a Unix timestamp, i.e. the number of seconds since
  *   January 1, 1970 UTC. The special value 0 can be used
  *   to include any measure, without ending limit.
  * </param>
  * <returns>
  *   an instance of <c>YDataSet</c>, providing access to historical
  *   data. Past measures can be loaded progressively
  *   using methods from the <c>YDataSet</c> object.
  * </returns>
  */
 public virtual YDataSetProxy get_recordedData(double startTime, double endTime)
 {
     if (_func == null)
     {
         throw new YoctoApiProxyException("No Sensor connected");
     }
     return(new YDataSetProxy(_func.get_recordedData(startTime, endTime)));
 }
Example #3
0
        internal YDataloggerContext(YSensor s, int start, int stop)
        {
            if (start < 0)
            {
                start = 0;
            }
            if (stop < 0)
            {
                stop = 0;
            }

            _sensor   = s;
            _dataset  = _sensor.get_recordedData(start, stop);
            _progress = _dataset.loadMore();
            _preview  = _dataset.get_preview();
        }
Example #4
0
        static void dumpSensor(YSensor sensor)
        {
            string fmt = "dd MMM yyyy hh:mm:ss,fff";

            Console.WriteLine("Using DataLogger of " + sensor.get_friendlyName());
            YDataSet dataset = sensor.get_recordedData(0, 0);

            Console.WriteLine("loading summary... ");
            dataset.loadMore();
            YMeasure summary = dataset.get_summary();
            String   line    =
                String.Format("from {0} to {1} : min={2:0.00}{5} avg={3:0.00}{5}  max={4:0.00}{5}",
                              summary.get_startTimeUTC_asDateTime().ToString(fmt),
                              summary.get_endTimeUTC_asDateTime().ToString(fmt), summary.get_minValue(),
                              summary.get_averageValue(), summary.get_maxValue(), sensor.get_unit());

            Console.WriteLine(line);
            Console.Write("loading details :   0%");
            int progress = 0;

            do
            {
                progress = dataset.loadMore();
                Console.Write(String.Format("\b\b\b\b{0,3:##0}%", progress));
            } while(progress < 100);
            Console.WriteLine("");
            List <YMeasure> details = dataset.get_measures();

            foreach (YMeasure m in details)
            {
                Console.WriteLine(
                    String.Format("from {0} to {1} : min={2:0.00}{5} avg={3:0.00}{5}  max={4:0.00}{5}",
                                  m.get_startTimeUTC_asDateTime().ToString(fmt),
                                  m.get_endTimeUTC_asDateTime().ToString(fmt), m.get_minValue(), m.get_averageValue(),
                                  m.get_maxValue(), sensor.get_unit()));
            }
        }
Example #5
0
        // the core function :  load data from datalogger to send it to the graph
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            // lets hide the graph wgile updating
            chart1.Visible    = false;
            comboBox1.Enabled = false;


            // remove any previous timed report call back
            for (int i = 0; i < comboBox1.Items.Count; i++)
            {
                ((YSensor)comboBox1.Items[i]).registerTimedReportCallback(null);
            }

            // allow zooming
            chart1.ChartAreas[0].CursorX.Interval                   = 0.001;
            chart1.ChartAreas[0].CursorX.IsUserEnabled              = true;
            chart1.ChartAreas[0].CursorX.IsUserSelectionEnabled     = true;
            chart1.ChartAreas[0].CursorX.AutoScroll                 = true;
            chart1.ChartAreas[0].AxisX.ScaleView.Zoomable           = true;
            chart1.ChartAreas[0].AxisX.ScrollBar.IsPositionedInside = true;

            int index = comboBox1.SelectedIndex;

            if (index >= 0)
            {
                clearGraph();
            }


            YSensor s = getSelectedSensor();

            if (s != null)
            {
                FirstPointDate = -1;
                LastPointDate  = -1;
                // some ui control
                loading.Visible = true;
                refreshDatloggerButton(null);
                progressBar.Visible = true;
                Status.Text         = "Loading data from datalogger...";
                for (int i = 0; i < 100; i++)
                {
                    Application.DoEvents();                          // makes sure the UI changes are repainted
                }
                // load data from datalogger
                YDataSet data     = s.get_recordedData(0, 0);
                int      progress = data.loadMore();
                while (progress < 100)
                {
                    try {
                        progressBar.Value = progress;
                    } catch { return; }

                    Application.DoEvents();
                    progress = data.loadMore();
                }

                // sets the unit (because ° is not a ASCII-128  character, Yoctopuce temperature
                // sensors report unit as 'C , so we fix it).
                chart1.ChartAreas[0].AxisY.Title     = s.get_unit().Replace("'C", "°C");
                chart1.ChartAreas[0].AxisY.TitleFont = new Font("Arial", 12, FontStyle.Regular);

                // send the data to the graph
                List <YMeasure> alldata = data.get_measures();
                for (int i = 0; i < alldata.Count; i++)
                {
                    chart1.Series[0].Points.AddXY(UnixTimeStampToDateTime(alldata[i].get_endTimeUTC()), alldata[i].get_averageValue());
                }

                // used to compute graph length
                if (alldata.Count > 0)
                {
                    FirstPointDate = alldata[0].get_endTimeUTC();
                    LastPointDate  = alldata[alldata.Count - 1].get_endTimeUTC();
                }
                setGraphScale();

                // restore UI
                comboBox1.Enabled   = true;
                progressBar.Visible = false;
                setSensorCount();
                s.set_reportFrequency("3/s");
                s.registerTimedReportCallback(newSensorValue);
                loading.Visible = false;
                chart1.Visible  = true;
                refreshDatloggerButton(s);
            }
        }