Hello,
I developed a web application using the MFToolkit webserver.
Using the emulator “Microsoft emulator 4.2” works fine, but using a “Fez Cobra II” motherboard I have two problems:
- randomly (but it happens often) the card remains frozen during “client = _listenSocket.Accept ();”, and no other connection is accepted.
To unlock it, I have to reboot, or in debugging I have to click “Break All” and then click “continue”, either way it works for some time and then refreeze. - the ExtendedWeakReference on reboot randomly does not retrieve the saved data.
Can I use a different memory area to store the configuration data? I would not use the SD card.
I spent several “sleepless nights” trying to solve, but since it works fine with the emulator, I do not know if I am in error, or the card has problems.
Can you help?
thanks in advance
Luca
The ENC28J60 module is configured so:
this.ethernet_ENC28J60 = new GHI.Premium.Net.EthernetENC28J60(SPI.SPI_module.SPI2, Pin.P1_10, Pin.P2_11, Pin.P1_9, 4000);
This is my ExtendedWeakReference implementation
[Serializable]
public sealed class ConfigurationData : IBDConfigParam
{
public ConfigurationData()
{
NetworkConfig = new NetworkConfig();
BoardClientConfig = new BoardClientConfig();
MailAgentConfig = new MailAgentConfig();
CentralId = BD_CENTRAL_ID;
}
private const String BD_CENTRAL_ID = "centralAlarm";
private CredentialCollection userList = new CredentialCollection();
public String CentralId { get; set; }
public String CentralAlarmProvider { get; set; }
public String InstallerCode { get; set; }
public NetworkConfig NetworkConfig { get; set; }
public IBoardClientConfig BoardClientConfig { get; set; }
public MailAgentConfig MailAgentConfig { get; set; }
public CredentialCollection UserList
{
get
{
return userList;
}
}
}
public class EWRPersistentData
{
private const int EWR_PERSISTENT_DATA_ID = 0;
/// <summary>
/// This static field refers to the extended weak reference object, in
// order to prevent it from being garbage-collected.
/// </summary>
private static ExtendedWeakReference persistentDataExtendedWeakReference;
/// <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 { }
private static object syncRoot = new object();
static EWRPersistentData()
{
persistentDataExtendedWeakReference =
ExtendedWeakReference.RecoverOrCreate(
typeof(TypeUniqueToOurApp), // The unique type that identifies the data.
EWR_PERSISTENT_DATA_ID, // The ID of the specific data item.
ExtendedWeakReference.c_SurviveBoot | ExtendedWeakReference.c_SurvivePowerdown); // The CLR should try to persist data across a reboot or power down.
// Indicate how important this data is. The CLR discards
// OkayToThrowAway items first, then NiceToHave items, then
// Important items, then Critical items, and finally System items.
// In practice, System items are virtually never discarded.
persistentDataExtendedWeakReference.Priority =
(Int32)ExtendedWeakReference.PriorityLevel.System;
}
/// <summary>
/// The execution entry point.
/// </summary>
public static ConfigurationData GetConfigurationData()
{
// Try to get the persisted data, initializing it if it is not
// available. The Target property of the extended weak reference
// must be cast to the actual type of the object. The Target
// property is cast to prevent the object from being
// garbage-collected unexpectedly.
ConfigurationData configurationData = (ConfigurationData)persistentDataExtendedWeakReference.Target;
if (configurationData == null)
{
lock (syncRoot)
{
configurationData = (ConfigurationData)persistentDataExtendedWeakReference.Target;
if (configurationData == null)
{
// The object could not be found in flash memory, so create the
// object and initialize it.
configurationData = new ConfigurationData();
SetPersistentData(configurationData);
#if (LOG)
Debug.Print("Created ConfigurationData");
#endif
}
}
}
else
{
#if (LOG)
Debug.Print("Successfully get ConfigurationData");
#endif
}
return configurationData;
}
/// <summary>
/// The execution entry point.
/// </summary>
public static void SetPersistentData(ConfigurationData persistentData)
{
// Set the Target property of the extended weak reference to the
// boot count object, triggering persistence.
lock (syncRoot)
{
persistentDataExtendedWeakReference.Target = persistentData;
Flush();
#if (LOG)
Debug.Print("Successfully write ConfigurationData");
#endif
}
// The CLR needs some time to asynchronously store the data in
// flash.
// The system provides no guarantee about when the data will
// actually be stored in flash memory. When the data is actually
// stored depends on the size of the object and the speed of the
// flash memory.
}
/// <summary>
/// The execution entry point.
/// </summary>
public static void Flush()
{
if (Microsoft.SPOT.Hardware.SystemInfo.SystemID.SKU != 3)
{
GHI.Premium.System.Util.FlushExtendedWeakReferences();
}
}
}