示例#1
0
 /**
  * <summary>
  *   Tests whether the byn file is valid for this module.
  * <para>
  *   This method is useful to test if the module needs to be updated.
  *   It is possible to pass a directory as argument instead of a file. In this case, this method returns
  *   the path of the most recent
  *   appropriate <c>.byn</c> file. If the parameter <c>onlynew</c> is true, the function discards
  *   firmwares that are older or
  *   equal to the installed firmware.
  * </para>
  * <para>
  * </para>
  * </summary>
  * <param name="path">
  *   the path of a byn file or a directory that contains byn files
  * </param>
  * <param name="onlynew">
  *   returns only files that are strictly newer
  * </param>
  * <para>
  * </para>
  * <returns>
  *   the path of the byn file to use or a empty string if no byn files matches the requirement
  * </returns>
  * <para>
  *   On failure, throws an exception or returns a string that start with "error:".
  * </para>
  */
 public virtual string checkFirmware(string path, bool onlynew)
 {
     if (_func == null)
     {
         throw new YoctoApiProxyException("No Module connected");
     }
     return(_func.checkFirmware(path, onlynew));
 }
示例#2
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);
        }