示例#1
0
        public override async Task <int> Run()
        {
            try {
                YModule m;

                await YAPI.RegisterHub(HubURL);

                m = YModule.FindModule(Target); // use serial or logical name
                if (await m.isOnline())
                {
                    if (!YAPI.CheckLogicalName(LogicalName))
                    {
                        WriteLine("Invalid name (" + LogicalName + ")");
                        return(-1);
                    }

                    await m.set_logicalName(LogicalName);

                    await m.saveToFlash(); // do not forget this

                    Write("Module: serial= " + await m.get_serialNumber());
                    WriteLine(" / name= " + await m.get_logicalName());
                }
                else
                {
                    Write("not connected (check identification and USB cable");
                }
            } catch (YAPI_Exception ex) {
                WriteLine("RegisterHub error: " + ex.Message);
            }
            YAPI.FreeAPI();
            return(0);
        }
示例#2
0
    // Token: 0x060000ED RID: 237 RVA: 0x0000656C File Offset: 0x0000476C
    public static YModule FirstModule()
    {
        int[]  v_fundescr = new int[1];
        int    dev        = 0;
        int    neededsize = 0;
        string serial     = null;
        string funcId     = null;
        string funcName   = null;
        string funcVal    = null;
        string errmsg     = "";
        int    size       = Marshal.SizeOf(v_fundescr[0]);
        IntPtr p          = Marshal.AllocHGlobal(Marshal.SizeOf(v_fundescr[0]));
        int    err        = YAPI.apiGetFunctionsByClass("Module", 0, p, size, ref neededsize, ref errmsg);

        Marshal.Copy(p, v_fundescr, 0, 1);
        Marshal.FreeHGlobal(p);
        if (YAPI.YISERR(err) | neededsize == 0)
        {
            return(null);
        }
        serial   = "";
        funcId   = "";
        funcName = "";
        funcVal  = "";
        errmsg   = "";
        if (YAPI.YISERR(YAPI.yapiGetFunctionInfo(v_fundescr[0], ref dev, ref serial, ref funcId, ref funcName, ref funcVal, ref errmsg)))
        {
            return(null);
        }
        return(YModule.FindModule(serial + "." + funcId));
    }
示例#3
0
        private void button1_Click(object sender, EventArgs e)
        {
            YModule m;
            string  errmsg = "";

            if (YAPI.RegisterHub("usb", ref errmsg) == YAPI.SUCCESS)
            {
                notifyIcon1.ShowBalloonTip(5, "PsymonWeather Beta", "Connection effectuée", ToolTipIcon.Info);
                timer1.Enabled             = true;
                btnConnexion.Enabled       = false;
                btnDeco.Enabled            = true;
                toolStripStatusLabel1.Text = "Connecté : Oui";
                m = YModule.FindModule("PsymonWeather");
                lblSerial.Text       = m.get_firmwareRelease().ToString();
                progressTemp.Minimum = 0;
                progressTemp.Maximum = 40;
                YTemperature temp = YTemperature.FindTemperature("temperature");
                progressTemp.Value = (int)temp.get_currentValue();
                lblTemp.Text       = string.Format("{0} °C", temp.get_currentValue());
                YHumidity humid = YHumidity.FindHumidity("humidity");
                lblHumid.Text = string.Format("{0} % d'humidité", humid.get_currentValue());
                YPressure pressure = YPressure.FindPressure("pressure");
                lblPressure.Text = string.Format("{0} Bar", pressure.get_currentValue());
                notifyIcon1.Text = string.Format("PsymonWeather Beta\nTemp. : {0}\nHumid. : {1}\nPress. : {2}", temp.get_currentValue(), humid.get_currentValue(), pressure.get_currentValue());
            }
            else
            {
                toolStripStatusLabel1.Text = "Connecté : Erreur";
                MessageBox.Show("Le module n'est pas branché.");
            }
        }
示例#4
0
        public static YModuleProxy FindModule(string name)
        {
            // cases to handle:
            // name =""  no matching unknwn
            // name =""  unknown exists
            // name != "" no  matching unknown
            // name !="" unknown exists
            YModule      func = null;
            YModuleProxy res  = (YModuleProxy)YFunctionProxy.FindSimilarUnknownFunction("YModuleProxy");

            if (name == "")
            {
                if (res != null)
                {
                    return(res);
                }
                res = (YModuleProxy)YFunctionProxy.FindSimilarKnownFunction("YModuleProxy");
                if (res != null)
                {
                    return(res);
                }
                func = YModule.FirstModule();
                if (func != null)
                {
                    name = func.get_hardwareId();
                    if (func.get_userData() != null)
                    {
                        return((YModuleProxy)func.get_userData());
                    }
                }
            }
            else
            {
                // allow to get module from the name of any function
                int p = name.IndexOf(".");
                if (p > 0)
                {
                    name = name.Substring(0, p) + ".module";
                }
                func = YModule.FindModule(name);
                if (func.get_userData() != null)
                {
                    return((YModuleProxy)func.get_userData());
                }
            }
            if (res == null)
            {
                res = new YModuleProxy(func, name);
            }
            if (func != null)
            {
                res.linkToHardware(name);
                if (func.isOnline())
                {
                    res.arrival();
                }
            }
            return(res);
        }
示例#5
0
        // link the instance to a real YoctoAPI object
        internal override void linkToHardware(string hwdName)
        {
            YModule hwd = YModule.FindModule(hwdName);

            // first redo base_init to update all _func pointers
            base_init(hwd, hwdName);
            // then setup Yocto-API pointers and callbacks
            init(hwd);
        }
示例#6
0
        static int upgradeSerialList(List <string> allserials)
        {
            string errmsg = "";

            foreach (string serial in allserials)
            {
                YModule module  = YModule.FindModule(serial);
                string  product = module.get_productName();
                string  current = module.get_firmwareRelease();

                // check if a new firmare is available on yoctopuce.com
                string newfirm = module.checkFirmware("www.yoctopuce.com", true);
                if (newfirm == "")
                {
                    Console.WriteLine(product + " " + serial + "(rev=" + current + ") is up to date");
                }
                else
                {
                    Console.WriteLine(product + " " + serial + "(rev=" + current +
                                      ") need be updated with firmare : ");
                    Console.WriteLine("    " + newfirm);
                    // execute the firmware upgrade
                    YFirmwareUpdate update = module.updateFirmware(newfirm);
                    int             status = update.startUpdate();
                    do
                    {
                        int newstatus = update.get_progress();
                        if (newstatus != status)
                        {
                            Console.WriteLine(newstatus + "% " + update.get_progressMessage());
                        }
                        YAPI.Sleep(500, ref errmsg);
                        status = newstatus;
                    } while (status < 100 && status >= 0);
                    if (status < 0)
                    {
                        Console.WriteLine("Firmware Update failed: " + update.get_progressMessage());
                        Environment.Exit(1);
                    }
                    else
                    {
                        if (module.isOnline())
                        {
                            Console.WriteLine(status + "% Firmware Updated Successfully!");
                        }
                        else
                        {
                            Console.WriteLine(status + " Firmware Update failed: module " + serial + "is not online");
                            Environment.Exit(1);
                        }
                    }
                }
            }
            return(0);
        }
示例#7
0
        static void Main(string[] args)
        {
            YModule m;
            string  errmsg = "";

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


            if (args.Length < 1)
            {
                usage();
            }

            m = YModule.FindModule(args[0]); // use serial or logical name

            if (m.isOnline())
            {
                if (args.Length >= 2)
                {
                    if (args[1].ToUpper() == "ON")
                    {
                        m.set_beacon(YModule.BEACON_ON);
                    }
                    if (args[1].ToUpper() == "OFF")
                    {
                        m.set_beacon(YModule.BEACON_OFF);
                    }
                }

                Console.WriteLine("serial:       " + m.get_serialNumber());
                Console.WriteLine("logical name: " + m.get_logicalName());
                Console.WriteLine("luminosity:   " + m.get_luminosity().ToString());
                Console.Write("beacon:       ");
                if (m.get_beacon() == YModule.BEACON_ON)
                {
                    Console.WriteLine("ON");
                }
                else
                {
                    Console.WriteLine("OFF");
                }
                Console.WriteLine("upTime:       " + (m.get_upTime() / 1000).ToString() + " sec");
                Console.WriteLine("USB current:  " + m.get_usbCurrent().ToString() + " mA");
                Console.WriteLine("Logs:\r\n" + m.get_lastLogs());
            }
            else
            {
                Console.WriteLine(args[0] + " not connected (check identification and USB cable)");
            }
            YAPI.FreeAPI();
        }
示例#8
0
    // Token: 0x060000E0 RID: 224 RVA: 0x000061CC File Offset: 0x000043CC
    public YModule nextModule()
    {
        string hwid = "";

        if (YAPI.YISERR(base._nextFunction(ref hwid)))
        {
            return(null);
        }
        if (hwid == "")
        {
            return(null);
        }
        return(YModule.FindModule(hwid));
    }
示例#9
0
    // Token: 0x060000B6 RID: 182 RVA: 0x00005A2C File Offset: 0x00003C2C
    public YModule get_module()
    {
        int    devdescr  = 0;
        string errmsg    = "";
        string serial    = "";
        string funcId    = "";
        string funcName  = "";
        string funcValue = "";
        int    fundescr  = YAPI.yapiGetFunction(this._className, this._func, ref errmsg);

        if (!YAPI.YISERR(fundescr) && !YAPI.YISERR(YAPI.yapiGetFunctionInfo(fundescr, ref devdescr, ref serial, ref funcId, ref funcName, ref funcValue, ref errmsg)))
        {
            return(YModule.FindModule(serial + ".module"));
        }
        return(YModule.FindModule("module_of_" + this._className + "_" + this._func));
    }
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            List <object> genericlist = e.Argument as List <object>;
            string        inFilename  = (string)genericlist[0];
            string        outFilename = (string)genericlist[1];
            string        serial      = (string)genericlist[2];
            YModule       m           = YModule.FindModule(serial);

            List <List <double> > angles = GetRecordList(m.get_serialNumber());
            VideoOSD osd = new VideoOSD(System.Drawing.Color.Aqua, inFilename);

            osd.setAngles(angles);
            osd.output(outFilename, backgroundWorker1);
            osd.release();

            e.Result = "done";            //return temp
        }
示例#11
0
        public override async Task <int> Run()
        {
            YModule m;
            string  errmsg = "";

            if (await YAPI.RegisterHub(HubURL) != YAPI.SUCCESS)
            {
                WriteLine("RegisterHub error: " + errmsg);
                return(-1);
            }
            m = YModule.FindModule(Target + ".module"); // use serial or logical name
            if (await m.isOnline())
            {
                if (Beacon)
                {
                    await m.set_beacon(YModule.BEACON_ON);
                }
                else
                {
                    await m.set_beacon(YModule.BEACON_OFF);
                }

                WriteLine("serial: " + await m.get_serialNumber());
                WriteLine("logical name: " + await m.get_logicalName());
                WriteLine("luminosity: " + await m.get_luminosity());
                Write("beacon: ");
                if (await m.get_beacon() == YModule.BEACON_ON)
                {
                    WriteLine("ON");
                }
                else
                {
                    WriteLine("OFF");
                }
                WriteLine("upTime: " + (await m.get_upTime() / 1000) + " sec");
                WriteLine("USB current: " + await m.get_usbCurrent() + " mA");
                WriteLine("Logs:\r\n" + await m.get_lastLogs());
            }
            else
            {
                WriteLine(Target + " not connected  on" + HubURL +
                          "(check identification and USB cable)");
            }
            YAPI.FreeAPI();
            return(0);
        }
示例#12
0
        static void HubDiscovered(string serial, string url)
        {
            // The call-back can be called several times for the same hub
            // (the discovery technique is based on a periodic broadcast)
            // So we use a dictionnary to avoid duplicates
            if (KnownHubs.Contains(serial))
            {
                return;
            }

            Console.WriteLine("hub found: " + serial + " (" + url + ")");

            // connect to the hub
            string msg = "";

            YAPI.RegisterHub(url, ref msg);

            //  find the hub module
            YModule hub = YModule.FindModule(serial);

            // iterate on all functions on the module and find the ports
            int fctCount = hub.functionCount();

            for (int i = 0; i < fctCount; i++)
            {
                // retreive the hardware name of the ith function
                string fctHwdName = hub.functionId(i);
                if (fctHwdName.Length > 7)
                {
                    if (fctHwdName.Substring(0, 7) == "hubPort")
                    {
                        // The port logical name is always the serial#
                        // of the connected device
                        string deviceid = hub.functionName(i);
                        Console.WriteLine("  " + fctHwdName + " : " + deviceid);
                    }
                }
            }
            // add the hub to the dictionnary so we won't have to
            // process is again.
            KnownHubs.Add(serial);

            // disconnect from the hub
            YAPI.UnregisterHub(url);
        }
示例#13
0
        static void Main(string[] args)
        {
            YModule m;
            string  errmsg = "";
            string  newname;

            if (args.Length != 2)
            {
                usage();
            }

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

            m = YModule.FindModule(args[0]); // use serial or logical name

            if (m.isOnline())
            {
                newname = args[1];
                if (!YAPI.CheckLogicalName(newname))
                {
                    Console.WriteLine("Invalid name (" + newname + ")");
                    Environment.Exit(0);
                }

                m.set_logicalName(newname);
                m.saveToFlash(); // do not forget this

                Console.Write("Module: serial= " + m.get_serialNumber());
                Console.WriteLine(" / name= " + m.get_logicalName());
            }
            else
            {
                Console.Write("not connected (check identification and USB cable");
            }
            YAPI.FreeAPI();
        }