Example #1
0
 /**
  * <summary>
  *   Configures error correction data points, in particular to compensate for
  *   a possible perturbation of the measure caused by an enclosure.
  * <para>
  *   It is possible
  *   to configure up to five correction points. Correction points must be provided
  *   in ascending order, and be in the range of the sensor. The device will automatically
  *   perform a linear interpolation of the error correction between specified
  *   points. Remember to call the <c>saveToFlash()</c> method of the module if the
  *   modification must be kept.
  * </para>
  * <para>
  *   For more information on advanced capabilities to refine the calibration of
  *   sensors, please contact [email protected].
  * </para>
  * <para>
  * </para>
  * </summary>
  * <param name="rawValues">
  *   array of floating point numbers, corresponding to the raw
  *   values returned by the sensor for the correction points.
  * </param>
  * <param name="refValues">
  *   array of floating point numbers, corresponding to the corrected
  *   values for the correction points.
  * </param>
  * <returns>
  *   <c>0</c> if the call succeeds.
  * </returns>
  * <para>
  *   On failure, throws an exception or returns a negative error code.
  * </para>
  */
 public virtual int calibrateFromPoints(double[] rawValues, double[] refValues)
 {
     if (_func == null)
     {
         throw new YoctoApiProxyException("No Sensor connected");
     }
     return(_func.calibrateFromPoints(new List <double>(rawValues), new List <double>(refValues)));
 }
Example #2
0
        //  This is the key function: it sets the calibration
        //  data in the device. Note: the parameters are written
        //  in the device RAM, if you want the calibration
        //  to be persistent, you have to call saveToflash();

        private void CalibrationChange(object sender, EventArgs e)
        {
            List <double> ValuesRaw = new List <double>();
            List <double> ValuesCal = new List <double>();
            List <int>    ParseRaw = new List <int>();
            List <int>    ParseCal = new List <int>();
            int           i = 0, j;

            if (functionsList.SelectedIndex < 0)
            {
                return;
            }

            while ((caledit[i].Text != "") && (rawedit[i].Text != "") && (i < 5))
            {
                ParseRaw = YAPI._decodeFloats(rawedit[i].Text);
                ParseCal = YAPI._decodeFloats(caledit[i].Text);
                if (ParseRaw.Count != 1 || ParseCal.Count != 1)
                {
                    break;
                }
                if (i > 0)
                {
                    if (ParseRaw[0] / 1000.0 <= ValuesRaw[i - 1])
                    {
                        break;
                    }
                }
                ValuesRaw.Add(ParseRaw[0] / 1000.0);
                ValuesCal.Add(ParseCal[0] / 1000.0);
                i++;
            }

            // some ui cosmetics: correct values are turned to green
            for (j = 0; j < i; j++)
            {
                caledit[j].BackColor = System.Drawing.Color.FromArgb(0xA0, 0xFF, 0xA0);
                rawedit[j].BackColor = System.Drawing.Color.FromArgb(0xA0, 0xFF, 0xA0);
            }
            for (j = i; j < 5; j++)
            {
                caledit[j].BackColor = System.Drawing.SystemColors.Window;
                rawedit[j].BackColor = System.Drawing.SystemColors.Window;
            }

            // send the calibration point to the device
            YSensor fct = (YSensor)functionsList.Items[functionsList.SelectedIndex];

            if (fct.isOnline())
            {
                fct.calibrateFromPoints(ValuesRaw, ValuesCal);
            }
        }