Here is a similar project (in VB) to demonstrate the use of secondary ram using a Microchip 23K256 32k byte SPI SRAM to store variables by name and log data. The project is here,
https://www.dropbox....7wf2/uxi2L9B_zk
It stores/retrieves the following types by name, String, Int16, Int32, Int64, UInt16, UInt32, UInt64, Single, Double, DateTime and Byte[]. For example to store and retrieve a variable,
Dim Data As SRAMStore = New SRAMStore()Dim StoredRecord As SRAMStore.FetchRecordDim MyDouble As Double = 0.000000012300011234964Data.StoreData("MyDouble", MyDouble)StoredRecord = Data.GetData("MyDouble")Debug.Print("MyDouble " & StoredRecord.StringData) --> MyDouble 1.2300011234963999e-08and also,Dim D As Double = Data.GetData("MyDouble", True).TypeDataDebug.Print("MyDouble, D = " & D.ToString)Dim MyDate As DateTime = DateTime.NowData.StoreData("MyDate", MyDate)Dim DT As DateTime = Data.GetData("MyDate", True).TypeDataDebug.Print("MyDate, DT = " & DT.ToString(DateTimeFormat))
Name/Value pairs are maintained using a hashtable where the Value is a symbol record structure. It will also log data by time stamp using a queue to keep order in the hashtable. With the exception of string and Byte[], all of the above types are converted to a string and the bytes of the string are stored. No attempt is made to optimize storage by deleting unwanted variables. New variables are simply added sequentially. Also, conversion of value types to a string for storing as bytes is inefficient, but easy.
The project is for a netduino Plus, but it should also run on any Netduino by changing to the appropriate reference and pins. The 23K256 driver is from the Codeshare on the TinyClr forum and was written by Savich.