Main Site Documentation

Storing Configuration Files on EMX


#1

Is it possible to store some small configuration files on the EMX Flash memory? Been searching all day looking for a solution. I see there is InternalFlashStorage but that only works for another module.

How do you make use of the 4.5MB of flash? Can that be used to store config files?

Many Thanks
Martin


#2

Check EWR. Extended Weak References(?)


#3

Excellent found it. Here is an example for anyone else looking:

(Program is the name of my class incase you wonder what typeof(Program) is.


/// <summary>
        /// This is the class that will be stored in Flash memory.  This class 
        /// must be serializable.
        /// </summary>
        [Serializable]
        private sealed class ConfigurationClass
        {
            public DateTime InstallDate;
        }

        /// <summary>
        /// The execution entry point.
        /// </summary>
        public static void Main()
        {
            // We are booting; try to retrieve the config
            ExtendedWeakReference EWRConfiguration =
                ExtendedWeakReference.RecoverOrCreate(
                    typeof(Program),  // The unique type that identifies the data.
                    0,                           // The ID of the specific data item.
                    ExtendedWeakReference.c_SurvivePowerdown); // The CLR should try to persist data across a reboot.

            // Indicate how important this data is.
            EWRConfiguration.Priority = (Int32)ExtendedWeakReference.PriorityLevel.System;

            // Try to get the persisted data.
            ConfigurationClass config = (ConfigurationClass)EWRConfiguration.Target;

            if (config == null)
            {
                // The object could not be found in flash memory, so create the 
                // object and initialize it.
                Debug.Print("No Configuration... Creating");
                config = new ConfigurationClass();
                config.InstallDate = DateTime.Now;
                EWRConfiguration.Target = config;
            }
            else
            {
                Debug.Print("Configuration Found. Install Date: " + config.InstallDate.ToString());
            }

            System.Threading.Thread.Sleep(2000);
        }


#4

Looks like you have the EWR stuff… But, in your code you do not set the system clock from the real time clock, so the stored date will be wrong.