예제 #1
0
 public void freeData()
 {
     _data.Clear();
     _preview.Clear();
     _progress = -1;
     _dataset  = null;
 }
        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()
                });
            }
        }
예제 #3
0
        private List <YMeasure> LoadQT(string hwid)
        {
            YQt      qt       = YQt.FindQt(hwid);
            YDataSet dataset  = qt.get_recordedData(0, 0);
            int      progress = 0;

            do
            {
                progress = dataset.loadMore();
            } while(progress < 100);


            Console.WriteLine("Using DataLogger of " + qt.get_friendlyName());
            YMeasure        summary = dataset.get_summary();
            List <YMeasure> res_bad = dataset.get_measures();
            List <YMeasure> res     = new List <YMeasure>();

            foreach (YMeasure m in res_bad)
            {
                if (m.get_startTimeUTC() > 100)
                {
                    res.Add(m);
                }
            }


            String line = String.Format("from {0} to {1} : min={2:0.00} avg={3:0.00}  max={4:0.00}",
                                        summary.get_startTimeUTC_asDateTime().ToString(fmt), summary.get_endTimeUTC_asDateTime().ToString(fmt), summary.get_minValue(), summary.get_averageValue(), summary.get_maxValue()
                                        );

            Console.WriteLine(line);
            return(res);
        }
예제 #4
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();
        }
    public virtual List <YDataSet> parse_dataSets(byte[] json)
    {
        List <string>   dslist = new List <string>();
        YDataSet        dataset;
        List <YDataSet> res = new List <YDataSet>();

        // may throw an exception
        dslist = this._json_get_array(json);
        res.Clear();
        for (int ii = 0; ii < dslist.Count; ii++)
        {
            dataset = new YDataSet(this);
            dataset._parse(dslist[ii]);
            res.Add(dataset);;
        }
        return(res);
    }
예제 #6
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()));
            }
        }
예제 #7
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);
            }
        }
예제 #8
0
    // Method used to cache DataStream objects (new DataLogger)
    public YDataStream _findDataStream(YDataSet dataset, string def)
    {
        string key = dataset.get_functionId() + ":" + def;
        if(_dataStreams.ContainsKey(key))
            return (YDataStream)_dataStreams[key];

        YDataStream newDataStream = new YDataStream(this, dataset, YAPI._decodeWords(def));
        _dataStreams.Add(key, newDataStream);
        return newDataStream;
    }
예제 #9
0
 //--- (generated code: YDataStream implementation)
 public virtual int _initFromDataSet(YDataSet dataset, List<int> encoded)
 {
     int val;
     int i;
     int maxpos;
     int iRaw;
     int iRef;
     double fRaw;
     double fRef;
     double duration_float;
     List<int> iCalib = new List<int>();
     // decode sequence header to extract data
     this._runNo = encoded[0] + (((encoded[1]) << (16)));
     this._utcStamp = encoded[2] + (((encoded[3]) << (16)));
     val = encoded[4];
     this._isAvg = (((val) & (0x100)) == 0);
     this._samplesPerHour = ((val) & (0xff));
     if (((val) & (0x100)) != 0) {
         this._samplesPerHour = this._samplesPerHour * 3600;
     } else {
         if (((val) & (0x200)) != 0) {
             this._samplesPerHour = this._samplesPerHour * 60;
         }
     }
     val = encoded[5];
     if (val > 32767) {
         val = val - 65536;
     }
     this._decimals = val;
     this._offset = val;
     this._scale = encoded[6];
     this._isScal = (this._scale != 0);
     this._isScal32 = (encoded.Count >= 14);
     val = encoded[7];
     this._isClosed = (val != 0xffff);
     if (val == 0xffff) {
         val = 0;
     }
     this._nRows = val;
     duration_float = this._nRows * 3600 / this._samplesPerHour;
     this._duration = (int) Math.Round(duration_float);
     // precompute decoding parameters
     this._decexp = 1.0;
     if (this._scale == 0) {
         i = 0;
         while (i < this._decimals) {
             this._decexp = this._decexp * 10.0;
             i = i + 1;
         }
     }
     iCalib = dataset.get_calibration();
     this._caltyp = iCalib[0];
     if (this._caltyp != 0) {
         this._calhdl = YAPI._getCalibrationHandler(this._caltyp);
         maxpos = iCalib.Count;
         this._calpar.Clear();
         this._calraw.Clear();
         this._calref.Clear();
         if (this._isScal32) {
             i = 1;
             while (i < maxpos) {
                 this._calpar.Add(iCalib[i]);
                 i = i + 1;
             }
             i = 1;
             while (i + 1 < maxpos) {
                 fRaw = iCalib[i];
                 fRaw = fRaw / 1000.0;
                 fRef = iCalib[i + 1];
                 fRef = fRef / 1000.0;
                 this._calraw.Add(fRaw);
                 this._calref.Add(fRef);
                 i = i + 2;
             }
         } else {
             i = 1;
             while (i + 1 < maxpos) {
                 iRaw = iCalib[i];
                 iRef = iCalib[i + 1];
                 this._calpar.Add(iRaw);
                 this._calpar.Add(iRef);
                 if (this._isScal) {
                     fRaw = iRaw;
                     fRaw = (fRaw - this._offset) / this._scale;
                     fRef = iRef;
                     fRef = (fRef - this._offset) / this._scale;
                     this._calraw.Add(fRaw);
                     this._calref.Add(fRef);
                 } else {
                     this._calraw.Add(YAPI._decimalToDouble(iRaw));
                     this._calref.Add(YAPI._decimalToDouble(iRef));
                 }
                 i = i + 2;
             }
         }
     }
     // preload column names for backward-compatibility
     this._functionId = dataset.get_functionId();
     if (this._isAvg) {
         this._columnNames.Clear();
         this._columnNames.Add(""+this._functionId+"_min");
         this._columnNames.Add(""+this._functionId+"_avg");
         this._columnNames.Add(""+this._functionId+"_max");
         this._nCols = 3;
     } else {
         this._columnNames.Clear();
         this._columnNames.Add(this._functionId);
         this._nCols = 1;
     }
     // decode min/avg/max values for the sequence
     if (this._nRows > 0) {
         if (this._isScal32) {
             this._avgVal = this._decodeAvg(encoded[8] + (((((encoded[9]) ^ (0x8000))) << (16))), 1);
             this._minVal = this._decodeVal(encoded[10] + (((encoded[11]) << (16))));
             this._maxVal = this._decodeVal(encoded[12] + (((encoded[13]) << (16))));
         } else {
             this._minVal = this._decodeVal(encoded[8]);
             this._maxVal = this._decodeVal(encoded[9]);
             this._avgVal = this._decodeAvg(encoded[10] + (((encoded[11]) << (16))), this._nRows);
         }
     }
     return 0;
 }
예제 #10
0
 public YDataStream(YFunction parent, YDataSet dataset, List<int> encoded)
 {
     this._parent   = parent;
     //--- (generated code: YDataStream attributes initialization)
     //--- (end of generated code: YDataStream attributes initialization)
     this._initFromDataSet(dataset, encoded);
 }
 internal YDataSetProxy(YDataSet objref)
 {
     _objref = objref;
     _objref.loadMore();
 }