Beispiel #1
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            string errmsg = "";

            if (hardwaredetect == 0)
            {
                YAPI.UpdateDeviceList(ref errmsg);
            }
            hardwaredetect = (hardwaredetect + 1) % 20;
            YAPI.HandleEvents(ref errmsg);
            if (sensor == null)
            {
                sensor = YSensor.FirstSensor();
            }
            if (sensor != null)
            {
                if (sensor.isOnline())
                {
                    label1.Text = sensor.get_friendlyName();
                    label2.Text = sensor.get_currentValue() + " " + sensor.get_unit();
                }
                else
                {
                    label1.Text = "OFFLINE";
                    label2.Text = "Sensor is offline";
                    sensor      = null;
                }
            }
        }
Beispiel #2
0
        // Methods

        /// <summary>
        /// Get sensor
        /// </summary>
        /// <returns></returns>
        protected override YSensor GetSensor()
        {
            string errmsg = "";

            if (hardwaredetect == 0)
            {
                YAPI.UpdateDeviceList(ref errmsg);
            }
            hardwaredetect = (hardwaredetect + 1) % 20;
            YAPI.HandleEvents(ref errmsg);
            YSensor sensor = YPressure.FirstPressure();

            if (sensor is null)
            {
                throw new SensorNotDetectedException();
            }
            else if (!sensor.isOnline())
            {
                throw new SensorOfflineException();
            }
            else
            {
                return(sensor);
            }
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Console dotNET Application 0.1.0");
            Console.WriteLine("--------------------------------");
            Console.WriteLine("");

            Console.WriteLine("Using Yoctopuce lib " + YAPI.GetAPIVersion());
            string errsmg = "";

            if (YAPI.RegisterHub("usb", ref errsmg) != YAPI.SUCCESS)
            {
                Console.WriteLine("Unable to register the USB port :" + errsmg);
                return;
            }

            YSensor sensor = YSensor.FirstSensor();

            if (sensor == null)
            {
                Console.WriteLine("No Yoctopuce sensor find on USB.");
                return;
            }

            YDisplay display = YDisplay.FirstDisplay();

            if (display == null)
            {
                Console.WriteLine("No Yoctopuce display find on USB.");
                return;
            }

            // display clean up
            display.resetAll();

            YDisplayLayer l1 = display.get_displayLayer(1);

            l1.hide();    // L1 is hidden, l2 stay visible
            int w = display.get_displayWidth();
            int h = display.get_displayHeight();


            while (sensor.isOnline() && display.isOnline())
            {
                string value = sensor.get_currentValue() + " " + sensor.get_unit();
                string name  = sensor.get_friendlyName();
                // display a text in the middle of the screen
                l1.clear();
                l1.selectFont("Large.yfm");
                l1.drawText(w / 2, h / 2, YDisplayLayer.ALIGN.CENTER, value);
                l1.selectFont("Small.yfm");
                l1.drawText(w - 1, h - 1, YDisplayLayer.ALIGN.BOTTOM_RIGHT, name);
                display.swapLayerContent(0, 1);
                Console.WriteLine(name + " ->" + value);
                YAPI.Sleep(500, ref errsmg);
            }
            YAPI.FreeAPI();
        }
Beispiel #4
0
        public static YSensorProxy FindSensor(string name)
        {
            // cases to handle:
            // name =""  no matching unknwn
            // name =""  unknown exists
            // name != "" no  matching unknown
            // name !="" unknown exists
            YSensor      func = null;
            YSensorProxy res  = (YSensorProxy)YFunctionProxy.FindSimilarUnknownFunction("YSensorProxy");

            if (name == "")
            {
                if (res != null)
                {
                    return(res);
                }
                res = (YSensorProxy)YFunctionProxy.FindSimilarKnownFunction("YSensorProxy");
                if (res != null)
                {
                    return(res);
                }
                func = YSensor.FirstSensor();
                if (func != null)
                {
                    name = func.get_hardwareId();
                    if (func.get_userData() != null)
                    {
                        return((YSensorProxy)func.get_userData());
                    }
                }
            }
            else
            {
                func = YSensor.FindSensor(name);
                if (func.get_userData() != null)
                {
                    return((YSensorProxy)func.get_userData());
                }
            }
            if (res == null)
            {
                res = new YSensorProxy(func, name);
            }
            if (func != null)
            {
                res.linkToHardware(name);
                if (func.isOnline())
                {
                    res.arrival();
                }
            }
            return(res);
        }
Beispiel #5
0
        public static YDataloggerContext init(string name, int start, int stop)
        {
            YSensor s = YSensor.FindSensor(name);

            if (!s.isOnline())
            {
                throw new Exception("sensor " + name + " is offline or does not exist.");
            }
            YDataloggerContext ctx = new YDataloggerContext(s, start, stop);

            return(ctx);
        }
Beispiel #6
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);
            }
        }
Beispiel #7
0
        private void choosenDeviceChanged()
        {
            YModule currentDevice;

            devicesList.Enabled = devicesList.Items.Count > 0;
            // clear the functions drop down
            functionsList.Items.Clear();
            functionsList.Enabled = devicesList.Enabled;

            if (!devicesList.Enabled)
            {
                unsupported_warning.Visible = false;
                nosensorfunction.Visible    = false;
                return;  // no device at all connected,
            }

            if (devicesList.SelectedIndex < 0)
            {
                devicesList.SelectedIndex = 0;
            }
            currentDevice = (YModule)devicesList.Items[devicesList.SelectedIndex];

            // populate the second drop down
            if (currentDevice.isOnline())
            {  // device capabilities inventory
                int fctcount = currentDevice.functionCount();
                for (int i = 0; i < fctcount; i++)
                {
                    string  fctName     = currentDevice.functionId(i);
                    string  fctFullName = currentDevice.get_serialNumber() + '.' + fctName;
                    YSensor fct         = YSensor.FindSensor(fctFullName);
                    // add the function in the second drop down
                    if (fct.isOnline())
                    {
                        functionsList.Items.Add(fct);
                    }
                }
            }
            functionsList.Enabled = functionsList.Items.Count > 0;
            if (functionsList.Enabled)
            {
                functionsList.SelectedIndex = 0;
            }

            refreshFctUI(true);
        }
Beispiel #8
0
        private void refreshFctUI(bool newone)
        {
            nosensorfunction.Visible   = false;
            toolStripStatusLabel1.Text = devicesList.Items.Count.ToString() + " device(s) found";

            if (!functionsList.Enabled)
            { // disable the UI
                ValueDisplay.Text      = "N/A";
                ValueDisplayUnits.Text = "-";
                RawValueDisplay.Text   = "-";
                EnableCalibrationUI(false);
                if (devicesList.Enabled)
                {
                    nosensorfunction.Visible = true;
                }
                else
                {
                    toolStripStatusLabel1.Text = "Plug a Yocto-device";
                }
                return;
            }

            YSensor fct = (YSensor)functionsList.Items[functionsList.SelectedIndex];

            if (newone)
            { // enable the ui
                EnableCalibrationUI(true);
                for (int i = 0; i < 5; i++)
                {
                    caledit[i].Text      = "";
                    caledit[i].BackColor = System.Drawing.SystemColors.Window;
                    rawedit[i].Text      = "";
                    rawedit[i].BackColor = System.Drawing.SystemColors.Window;
                }
                DisplayCalPoints(fct);
            }

            if (fct.isOnline())
            {
                DisplayValue(fct);
            }
        }
 protected static void _UpdateTimedReportCallbackList(YSensor func, Boolean add)
 {
     if (add)
     {
         func.isOnline();
         if (!_TimedReportCallbackList.Contains(func))
         {
             _TimedReportCallbackList.Add(func);
         }
     }
     else
     {
         _TimedReportCallbackList.Remove(func);
     }
 }