EWR on G400-S

I am using EWR to save serial number, revision and mod for a custom G400 based PCB, so far with a resounding lack of success. The G400 should have plenty of room to implement ExtendedWeakReferences, so I’m assuming this is not a result of EWR being silently disabled.

Before you start yelling at me please know that I did look at all of the EWR posts I could find, both on the GHI forums and elsewhere. None helped.

Here is my code:

public static class Nvm
{
    [Serializable]
    public class AppSettings
    {
        public int SerialNumber;
        public int Rev;
        public int Mod;
    }

    public static void Write(AppSettings settings)
    {
        var ewr = ExtendedWeakReference.RecoverOrCreate(typeof(AppSettings), 0, ExtendedWeakReference.c_SurvivePowerdown);
        ewr.Priority = (int)ExtendedWeakReference.PriorityLevel.Important;
        ewr.Target = settings;              // This SHOULD write settings to NVM
        ExtendedWeakReference.FlushAll();   // Attempt 1, supposed to hold execution and perform all queued NVM writes
        Thread.Sleep(5000);                 // Attempt 2, leav enough idle time to perform queued NVM writes
    }

    public static AppSettings Read()
    {
        var ewr = ExtendedWeakReference.RecoverOrCreate(typeof(AppSettings), 0, ExtendedWeakReference.c_SurvivePowerdown);
        return (ewr.Target as AppSettings) ?? new AppSettings();  // Creates new AppSettings if target is null or not of type AppSettings
    }
}

Even after I save an AppSettings object to NVM, when I try to read it back, either in the same session or after power cycle, it always comes back null. Any ideas?

I believe that there is a sample project for EWR installed with VS.

According to previous forum posts there was an EWR sample installed with NETMF 4.2, but other than the FlushAll() change that came with NETMF 4.3 I’ve implemented the core of that example. I can’t see what I’m doing wrong, unless G400 doesn’t support EWR for some reason.

@ bigtwisty - Our apologies for the delay. G400 does support EWR and it should work for you. Keep in mind though that EWR is not meant to be a reliable data store. Data can and sometimes is lost. Storing the type of information you plan to in EWR is not advised given its unreliabilty. Something like https://www.ghielectronics.com/community/forum/topic?id=19121&page=2#msg191898 may work better for you.

That said, can you try the example in http://netmf.codeplex.com/SourceControl/latest#client_v4_3/Product/Samples/ExtendedWeakReferences/ExtendedWeakReferences.cs without modification on a freshly flashed board and see if it runs?

Is there an update for the first link in John_Brochue’s reply.
I tried adding old. to the link.

  • Phil

It was referencing the Configuration class we added in one of the later NETMF SDKs which allows you to read and write from the internal config store.

Thanks very much for responding, as we have been using extended weak references with .NET MF 4.3 on the G400 and G120 for about three years now. For serial number, bcdUSB field, and our internal USB hub port enable/disable bit map.

Works great, and as expected.

Phil