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?