I just tried to use ExtendedWeakReference on a FEZ Spider (MF 4.2, Firmware 4.2.9) with the code given in the MF sample or I read in the forum. Unfortunately it doesn’t save anything. The target of ExtendedWeakReference.RecoverOrCreate(…) is always null. Is there anything to enable it?
Code - writing
var ewr = ExtendedWeakReference.RecoverOrCreate(typeof(TypeUniqueToOurApp), 0, ExtendedWeakReference.c_SurvivePowerdown);
ewr.Priority = (Int32)ExtendedWeakReference.PriorityLevel.Critical;
var numBoots = ewr.Target as NumBoots;
if (numBoots == null)
numBoots = new NumBoots(1);
else
numBoots.BootCount += 1;
ewr.Target = numBoots;
Code - reading
var ewr = ExtendedWeakReference.RecoverOrCreate(typeof(TypeUniqueToOurApp), 0, ExtendedWeakReference.c_SurvivePowerdown);
var numBoots = ewr.Target as NumBoots;
numBoots is always null!
Fully qualified type names help a littel bit, e.g. data will be kept as long the machine is running. But the data didn’t survive rebooting even I set the flag
ExtendedWeakReference.c_SurvivePowerdown
I also was playing ouround with
ewr.PushBackIntoRecoverList();
Nothing helped. After rebooting (and deploying) the same code, the call
ExtendedWeakReference.RecoverOrCreate(...)
couldn’t recover the data. The code seems to be too easy to make any mistakes!
@ andre - thanks for the “101010” icon - I didn’t see it before…
No, this sample doesn’t work either. First I had to change the sample and use the fully qualified type. I could
RecoverOrCreate
the data until I rebooted the FEZ. Then everything was gone.
Thanks for your answer. I probably won’t use the flash memory, even if it would work, because as I understood the manual, it’s not guaranteed that the data would survive anyway. Probably it’s better to store data on a sd card.
Have you been able to fix your problem with the writing of data on the Spider internal Flash memory ?
I do face the same problem. I used the code you talk about here and now with the latest version of the SDKs, nothing is stored in the Flash Memory, and the call to RecoverOrCreate always returns NULL.
OK. The demo code works also fine on my spider. So that means that it’s my code that does not work.
A couple of questions to figure out what’s going wrong :
How big can be the object that you put in Flash ? I actually put in a single classe all the configuration I need for my project. It’s more than a hundred parameters, mostly short strings
What exactly can be serialized and what cannot ? For example, can a DateTime object be serialized ?
The object that can be serialized for extended weak reference have the serializable attribute.
As an example, check the attribute for array list and hashtable int the system collection namespace.
How big can be the object… this is a real problem nobody can say how to compute the size of data that we can pass to EWR. However you can reduce size using [serializationhint].