Main Site Documentation

Save settings to Mountaineer ETH flash


#1

Hello,

what is the best way to save settings to the the flash memory?

I’ve tried the ExtendedWeakReference class, but my settings won’t survive power down, although I’ve set:

ExtendedWeakReference.c_SurvivePowerdown 

I have a project with one Mountaineer ETH mainboard, one BrightSign HD220 Video-Player and a Windows Service installed on a Windows Server 2012.

The Mountaineer sends a http request to the Windows Service, the Service responds with a json-file, which contains the IP of the Brightsign-Player.

I want to save the IP of the Brightsign Player in flash. In case of the Windows Server isn’t available, the Mountaineer can load the IP-Address from flash so that the communication between the Mountaineer and the Brightsign-Player works.

I hope you understand what I want to do.

Thank you in advance.


#2

Thank you for this answere. Both flags are already set.
A sleep of 3000 ms after the

EWR.Target = Settings;

is performed aswell.


#3

I save the settings in a seperate thread.


        private Settings m_Settings;

        /// <summary>
        /// This static field refers to the extended weak reference object, in 
        // order to prevent it from being garbage-collected.
        /// </summary>
        private static ExtendedWeakReference StaticSettingsExtendedWeakReference;

        /// <summary>
        /// This private class is used as a signature to uniquely identify data 
        /// we own.  It is not necessary to create a dedicated class for this 
        /// purpose.
        /// </summary>
        private static class TypeUniqueToOurApp { }

        /// <summary>
        /// This is the class that will be stored in Flash memory.  This class 
        /// must be serializable.
        /// </summary>
        [Serializable]
        private sealed class Settings
        {
            /// <summary>
            /// This method sets the number of boots.
            /// </summary>
            /// <param name="ipAddress">The number of times the device has been 
            /// booted.</param>
            public Settings(byte[] ipAddress)
            {
                IpAddress = ipAddress;
            }

            // Fields must be serializable.
            public byte[] IpAddress;
        }

private bool InitFlashMemory()
        {
            try
            {
                StaticSettingsExtendedWeakReference= ExtendedWeakReference.RecoverOrCreate(typeof(TypeUniqueToOurApp), 0, ExtendedWeakReference.c_SurvivePowerdown);
                StaticSettingsExtendedWeakReference.Priority = (Int32)ExtendedWeakReference.PriorityLevel.System;
                return true;
            }
            catch
            {
                return false;
            }
        }

private void StartSaveSettingThread()
        {
            m_SaveConfigToFlashThread = new Thread(SaveSetting);
            m_SaveConfigToFlashThread.Start();
        }

private void SaveSetting()
        {
            if (m_PlayerIP.Length > 0)
            {
                m_Settings = new Settings(m_PlayerIP);
                while (StaticSettingsExtendedWeakReference.Target == null)
                {
                    StaticSettingsExtendedWeakReference.Target = m_Settings;
                    Thread.Sleep(3000);
                }
                StaticSettingsExtendedWeakReference.PushBackIntoRecoverList();
                WriteLogAndDisplay("Settings saved!", true);
            }
        }


Edit: The “StaticSettingsExtendedWeakReference” was setted wrong. The one above is correct now.


#4

That unit has •8 MB external Flash, for data logging.

please see this thread for how to access it
Works way better than EWR.
http://www.ghielectronics.com/community/forum/topic?id=8710