Main Site Documentation

My application update by remotely, need ur help, FEZ Pand II


#1

i have gsm modem by this i want to connect windows service, and download new application version file, and save it into SD, after download i want to update my application from SD, so how to do this can someone help me.
FEZ Panda II.


#2

For gsm:

http://code.tinyclr.com/project/278/gsm-driver/

For the rest of it:

take a look at Pyxis2 code it has everything you need.


#3

thanks but i dont need gsm modem driver,
an one question how i can get my app hex file?


#4

Read documentation:

http://www.ghielectronics.com/downloads/NETMF/Library%20Documentation/html/53c9fe92-8150-bd36-e2de-bf4fc6f13f8f.htm

Hint: Paragraph title is “Obtaining the Application File”


#5

need your help please :((
here is my code which don’t works :frowning:

here comes exeption:
" SystemUpdate.ApplicationUpdate.Start(); "


        #region Class Level Variables

        private static Program mInstance;
        private static InterruptPort mUpdateBTN;
        private static PersistentStorage mSDStorage;
        private static bool Installing = false;

        #endregion

        #region Event Handlers

        private static void OnInterrupt(uint data1, uint data2, DateTime time)
        {
            if (PersistentStorage.DetectSDCard())
            {
                mInstance.StartUpdate();
            }
        }

        #endregion

        #region Methods

        public static void Main()
        {
            mInstance = new Program();

            mInstance.GetMode();
            if (SystemUpdate.GetMode() != SystemUpdate.SystemUpdateMode.Application)
            {
                throw new InvalidOperationException("We are not in application mode!");
            }
            if (PersistentStorage.DetectSDCard())
            {
                mSDStorage = new PersistentStorage("SD");
                mSDStorage.MountFileSystem();
            }

            mUpdateBTN = new InterruptPort((Cpu.Pin)FEZ_Pin.Digital.LDR, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);
            mUpdateBTN.OnInterrupt += OnInterrupt;
            Debug.Print("This is the normal application working...");

            Thread.Sleep(Timeout.Infinite);
        }

        private void StartUpdate()
        {
            var mFileName = GetRootDirectory() + "\\app.hex";
            Debug.Print("Going To Read Data");
            InstallUpdate(mFileName);
        }

        private string GetRootDirectory()
        {
            var volumes = VolumeInfo.GetVolumes();
            if (volumes.Length > 0)
            {
                return volumes[0].RootDirectory;
            }
            return "";
        }

        private void GetMode()
        {
            var mode = SystemUpdate.GetMode();
            Debug.Print("Current Mode Is: " + mode);

            switch (mode)
            {
                case SystemUpdate.SystemUpdateMode.NonFormatted:
                    SystemUpdate.EnableBootloader();
                    break;
                case SystemUpdate.SystemUpdateMode.Bootloader:
                    throw new Exception("Invalid Boot Mode!");
            }
        }

        private void InstallUpdate(string sPath)
        {
            bool bComplete = true;
            Installing = true;

            // start update
            SystemUpdate.ApplicationUpdate.Start();
            if (!InstallFile(sPath))
            {
                Debug.Print("FAILED");
                bComplete = false;
                return;
            }
            try
            {
                File.Delete(sPath);
            }
            catch
            {
                //ignore
            }

            if (bComplete)
            {
                SystemUpdate.ApplicationUpdate.End();
            }
            SystemUpdate.AccessApplication();
        }

        private bool InstallFile(string sFile)
        {
            try
            {
                FileStream file = new FileStream(sFile, FileMode.Open, FileAccess.Read);
                byte[] buffer = new byte[10 * 1024];
                int length;
                do
                {
                    length = file.Read(buffer, 0, buffer.Length);
                    SystemUpdate.ApplicationUpdate.Write(buffer, 0, length);

                } while (length == buffer.Length);

                file.Close();
                return true;
            }
            catch
            {
                return false;
            }
        }

#6

I don’t see where you call AccessBootloader. Follow the instructions in the documentation. Have you looked at Pyxis2 code?


#7

i had AccessBootloader but it gives me exeption and then removed it
only what i need is to update my program from sd, and someone has some small source code.
i have Fez Panda II.
yes i looked at pyxis code but there i could not find there also accessbootloader.

this is my new source code but still nothing :frowning:

   private void EnsureLogFile(string path)
        {
            if (!File.Exists(path))
            {
                File.Create(path).Dispose();
            }
        }

        private void LogToFile(string input)
        {
            var filename = GetRootDirectory() + "\\" + DateTime.Now.ToString("ddMMyyyy") + ".log";
            EnsureLogFile(filename);
            using (var fs = new FileStream(filename, FileMode.Append, FileAccess.Write))
            {
                var sw = new StreamWriter(fs);
                Debug.Print("writing: " + input);
                sw.WriteLine(input);
                sw.Close();
                fs.Close();
            }
        }

        private string GetFirmwarePath()
        {
            var fileName = GetRootDirectory();
            if (fileName != null)
            {
                fileName += "\\" + "app.hex";
                if (File.Exists(fileName))
                {
                    return fileName;
                }
            }
            return null;
        }

        public static void Main()
        {
            mInstance = new Program();

            mSDStorage = new PersistentStorage("SD");
            mSDStorage.MountFileSystem();

            SystemUpdate.SystemUpdateMode mode = SystemUpdate.GetMode();

            mInstance.LogToFile("EMX starts. Mode: " + mode.ToString());

            // Allow firmware on the board to be upgradable.
            if (mode == SystemUpdate.SystemUpdateMode.NonFormatted)
            {
                SystemUpdate.EnableBootloader();

                // Force a hard reboot
                PowerState.RebootDevice(false);
            }

            // Start to upgrade firmware
            if (mode == SystemUpdate.SystemUpdateMode.Bootloader)
            {
                mInstance.LogToFile("Start to upgrade ...");
                // Force mount all removable disks...

                var firmwarePath = mInstance.GetFirmwarePath();
                if (firmwarePath != null)
                {
                    // Start to upgrade
                    try
                    {
                        SystemUpdate.ApplicationUpdate.Start();

                        using (FileStream fs = new FileStream(firmwarePath, FileMode.Open, FileAccess.Read))
                        {
                            byte[] buffer = new byte[10 * 1024];
                            int len = 0;

                            do
                            {
                                len = fs.Read(buffer, 0, buffer.Length);
                                SystemUpdate.ApplicationUpdate.Write(buffer, 0, len);
                            } while (len == buffer.Length);

                            SystemUpdate.ApplicationUpdate.End();
                        }
                    }
                    catch (Exception ex)
                    {
                        mInstance.LogToFile("Failed to upgrade.");
                    }

                }

                //Restart
                SystemUpdate.AccessApplication();
            }

            if (mode == SystemUpdate.SystemUpdateMode.Application)
            {
                if (PersistentStorage.DetectSDCard())
                {
                    if (File.Exists(mInstance.GetFirmwarePath()))
                    {
                        mInstance.LogToFile("Prepare to upgrade. Rebooting ...");
                        SystemUpdate.AccessBootloader();
                    }
                }

                Thread.Sleep(5000);
            }
        }

#8

To find what you need in Pyxis 2:

Enabling/Accessing: /Progam.cs

Updating from SD: Pyxis2Updater/Program.cs