Esempio n. 1
0
        static void Main(string[] args)
        {
            string errmsg = "";

            if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS)
            {
                Console.WriteLine("RegisterHub error: " + errmsg);
                Environment.Exit(1);
            }

            YSensor sensor;

            if (args.Length == 0 || args[0] == "any")
            {
                sensor = YSensor.FirstSensor();
                if (sensor == null)
                {
                    Console.WriteLine("No module connected (check USB cable)");
                    Environment.Exit(1);
                }
            }
            else
            {
                sensor = YSensor.FindSensor(args[0]);
                if (!sensor.isOnline())
                {
                    Console.WriteLine("Sensor " + sensor + " is not connected (check USB cable)");
                    Environment.Exit(1);
                }
            }
            dumpSensor(sensor);
            YAPI.FreeAPI();
            Console.WriteLine("Done. Have a nice day :)");
        }
Esempio n. 2
0
        async Task dispatcherTimer_Tick()
        {
            try {
                if (hardwaredetect == 0)
                {
                    await YAPI.UpdateDeviceList();
                }

                hardwaredetect = (hardwaredetect + 1) % 20;
                await YAPI.HandleEvents();

                if (sensor == null)
                {
                    sensor = YSensor.FirstSensor();
                }
                if (sensor != null)
                {
                    HwIdTextBox.Text = await sensor.get_friendlyName();

                    TempTextBox.Text = await sensor.get_currentValue() + await sensor.get_unit();
                }
            } catch (YAPI_Exception ex) {
                HwIdTextBox.Text = "Sensor is offline";
                TempTextBox.Text = "OFFLINE";
                sensor           = null;
            }
        }
Esempio n. 3
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;
                }
            }
        }
Esempio n. 4
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();
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
        /**
         * <summary>
         *   Enumerates all functions of type Sensor available on the devices
         *   currently reachable by the library, and returns their unique hardware ID.
         * <para>
         *   Each of these IDs can be provided as argument to the method
         *   <c>YSensor.FindSensor</c> to obtain an object that can control the
         *   corresponding device.
         * </para>
         * </summary>
         * <returns>
         *   an array of strings, each string containing the unique hardwareId
         *   of a device function currently connected.
         * </returns>
         */
        public static new string[] GetSimilarFunctions()
        {
            List <string> res = new List <string>();
            YSensor       it  = YSensor.FirstSensor();

            while (it != null)
            {
                res.Add(it.get_hardwareId());
                it = it.nextSensor();
            }
            return(res.ToArray());
        }
Esempio n. 7
0
        async Task deviceArrival(YModule m)
        {
            string serial = await m.get_serialNumber();

            Output.Text += "Device arrival : " + serial + "\n";
            await m.registerLogCallback(deviceLog);

            await m.registerConfigChangeCallback(configChange);

            await m.registerBeaconCallback(beaconChange);

            // First solution: look for a specific type of function (eg. anButton)
            int fctcount = await m.functionCount();

            for (int i = 0; i < fctcount; i++)
            {
                string hardwareId = serial + "." + await m.functionId(i);

                if (hardwareId.IndexOf(".anButton") >= 0)
                {
                    Output.Text += "- " + hardwareId + "\n";
                    YAnButton anButton = YAnButton.FindAnButton(hardwareId);
                    await anButton.registerValueCallback(anButtonValueChangeCallBack);
                }
            }

            // Alternate solution: register any kind of sensor on the device
            YSensor sensor = YSensor.FirstSensor();

            while (sensor != null)
            {
                YModule module = await sensor.get_module();

                if (await module.get_serialNumber() == serial)
                {
                    string hardwareId = await sensor.get_hardwareId();

                    Output.Text += "- " + hardwareId + "\n";
                    string unit = await sensor.get_unit();

                    await sensor.set_userData(unit);

                    await sensor.registerValueCallback(sensorValueChangeCallBack);

                    await sensor.registerTimedReportCallback(sensorTimedReportCallBack);
                }

                sensor = sensor.nextSensor();
            }
        }
Esempio n. 8
0
        public override async Task <int> Run()
        {
            DateTime _epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);

            try {
                await YAPI.RegisterHub(HubURL);

                // Enumerate all connected sensors
                YSensor        sensor;
                List <YSensor> sensorList = new List <YSensor>();
                sensor = YSensor.FirstSensor();
                while (sensor != null)
                {
                    sensorList.Add(sensor);
                    sensor = sensor.nextSensor();
                }

                if (sensorList.Count == 0)
                {
                    WriteLine("No Yoctopuce sensor connected (check USB cable)");
                }
                else
                {
                    // Generate consolidated CSV output for all sensors
                    YConsolidatedDataSet data   = new YConsolidatedDataSet(0, 0, sensorList);
                    List <Double>        record = new List <Double>();
                    while (await data.nextRecord(record) < 100)
                    {
                        string line = _epoch.AddSeconds(record[0]).ToString("yyyy-MM-ddTHH:mm:ss.fff");
                        for (int i = 1; i < record.Count; i++)
                        {
                            line += String.Format(";{0:0.000}", record[i]);
                        }
                        WriteLine(line);
                    }
                }
            } catch (YAPI_Exception ex) {
                WriteLine("Error:" + ex.Message);
            }


            YAPI.FreeAPI();
            return(0);
        }
Esempio n. 9
0
        static void Main(string[] args)
        {
            DateTime _epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            string   errmsg = "";

            if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS)
            {
                Console.WriteLine("RegisterHub error: " + errmsg);
                Environment.Exit(1);
            }

            // Enumerate all connected sensors
            List <YSensor> sensorList = new List <YSensor>();
            YSensor        sensor;

            sensor = YSensor.FirstSensor();
            while (sensor != null)
            {
                sensorList.Add(sensor);
                sensor = sensor.nextSensor();
            }
            if (sensorList.Count == 0)
            {
                Console.WriteLine("No Yoctopuce sensor connected (check USB cable)");
                Environment.Exit(1);
            }

            // Generate consolidated CSV output for all sensors
            YConsolidatedDataSet data   = new YConsolidatedDataSet(0, 0, sensorList);
            List <double>        record = new List <double>();

            while (data.nextRecord(record) < 100)
            {
                string line = _epoch.AddSeconds(record[0]).ToString("yyyy-MM-ddTHH:mm:ss.fff");
                for (int i = 1; i < record.Count; i++)
                {
                    line += String.Format(";{0:0.000}", record[i]);
                }
                Console.WriteLine(line);
            }

            YAPI.FreeAPI();
        }
Esempio n. 10
0
        public Form1()
        {
            InitializeComponent();
            _t.Interval = 1000;
            _t.Enabled  = true;
            _t.Tick    += (sender, args) =>
            {
                YAPI.HandleEvents(ref _err);
            };

            YAPI.RegisterHub("USB", ref _err);
            YAPI.UpdateDeviceList(ref _err);
            var sensor = YSensor.FirstSensor();

            sensor.registerTimedReportCallback(timedReport);
            _t.Start();

            tbLux.Text = sensor.FriendlyName;
        }
Esempio n. 11
0
        static void deviceArrival(YModule m)
        {
            string serial = m.get_serialNumber();

            Console.WriteLine("Device arrival : " + serial);
            m.registerLogCallback(deviceLog);
            m.registerConfigChangeCallback(configChange);
            m.registerBeaconCallback(beaconChange);

            // First solution: look for a specific type of function (eg. anButton)
            int fctcount = m.functionCount();

            for (int i = 0; i < fctcount; i++)
            {
                string hardwareId = serial + "." + m.functionId(i);
                if (hardwareId.IndexOf(".anButton") >= 0)
                {
                    Console.WriteLine("- " + hardwareId);
                    YAnButton anButton = YAnButton.FindAnButton(hardwareId);
                    anButton.registerValueCallback(anButtonValueChangeCallBack);
                }
            }

            // Alternate solution: register any kind of sensor on the device
            YSensor sensor = YSensor.FirstSensor();

            while (sensor != null)
            {
                if (sensor.get_module().get_serialNumber() == serial)
                {
                    string hardwareId = sensor.get_hardwareId();
                    Console.WriteLine("- " + hardwareId);
                    string unit = sensor.get_unit();
                    sensor.set_userData(unit);
                    sensor.registerValueCallback(sensorValueChangeCallBack);
                    sensor.registerTimedReportCallback(sensorTimedReportCallBack);
                }

                sensor = sensor.nextSensor();
            }
        }
Esempio n. 12
0
        // automatically called each time a new yoctopuce device is plugged
        public void deviceArrival(YModule m)
        {   // new device just arrived, lets enumerate all sensors and
            // add the one missing to the combobox
            YSensor s = YSensor.FirstSensor();

            while (s != null)
            {
                if (!comboBox1.Items.Contains(s))
                {
                    int index = comboBox1.Items.Add(s);
                }
                s = s.nextSensor();
            }
            comboBox1.Enabled = comboBox1.Items.Count > 0;
            if ((comboBox1.SelectedIndex < 0) && (comboBox1.Items.Count > 0))
            {
                comboBox1.SelectedIndex = 0;
            }

            setSensorCount();
        }