We have introduced a new feature in the MBN Core, known as Storage class.
In short : this class allows the use of different kinds of memories to be used with a single set of instructions, either for simple storage or for file-system (using the TinyFileSystem(*) driver).
Here is a sample code that demonstrate the (ease of) use of the new Storage feature :
private static Storage _storage1, _storage2, _storage3, _storage4;
public static void Main()
{
_storage1 = new FRAMClick(Hardware.SocketTwo);
_storage2 = new FlashClick(Hardware.SocketOne);
_storage3 = new OnboardFlash();
_storage4 = new EEpromClick(Hardware.SocketOne, memorySize: 256);
TestSimpleStorage(_storage1);
TestSimpleStorage(_storage2);
TestTFS(_storage3);
TestTFS(_storage4);
// We could also have used TFS with the FRAM and Flash Click boards, without changing anything else :
TestTFS(_storage1); // See how simple it is
TestTFS(_storage2);
Thread.Sleep(Timeout.Infinite);
}
private static void TestSimpleStorage(Storage storage)
{
var bArray = new Byte[3];
storage.WriteByte(10, 200);
Debug.Print("Read byte @ 10 (should be 200) : " + storage.ReadByte(10));
storage.WriteByte(200, 201);
Debug.Print("Read byte @ 200 (should be 201) : " + storage.ReadByte(200));
storage.WriteData(400, new Byte[] { 100, 101, 102 }, 0, 3);
storage.ReadData(400, bArray, 0, 3);
Debug.Print("Read 3 bytes starting @ 400 (should be 100, 101, 102) : " + bArray[0] + ", " + bArray[1] + ", " + bArray[2]);
}
private static void TestTFS(Storage storage)
{
var tfs = new TinyFileSystem(storage);
if (tfs.CheckIfFormatted())
{
Debug.Print("Filesystem OK. Mounting...");
tfs.Mount();
Debug.Print(" Now reading settings.dat file...");
if (!tfs.Exists("settings.dat"))
{
Debug.Print("File does not exist");
return;
}
using (var fs = tfs.Open("settings.dat", FileMode.Open))
using (var rdr = new StreamReader(fs))
{
string line;
while ((line = rdr.ReadLine()) != null)
{
Debug.Print(line);
}
}
}
else
{
Debug.Print("Formatting");
tfs.Format();
Debug.Print("Creating file");
using (var fs = tfs.Create("settings.dat"))
{
using (var wr = new StreamWriter(fs))
{
wr.WriteLine("<settings>");
wr.WriteLine("InitialPosX=200");
wr.WriteLine("InitialPosY=150");
wr.WriteLine("</settings>");
wr.Flush();
fs.Flush();
}
}
Debug.Print("FileCreated");
}
}
Here is a screenshot of the result on a 256KB EEprom Click board :

What does that mean ? It means that you can use almost any memory storage device with MBN and store data on it in a common and very simple way. As long as you know their capacities and how to read/write an array of byte on it, then you are ready !
And now that the drivers already exist for the most common memory kinds (see http://www.mikrobusnet.org/downloads-2 ), you even only have to change the capacity in one driver to have a storage device available in seconds !
Of course, you should be careful to not use the same chip with both TFS and simple storage. Their uses are obviously mutually exclusive.
An example of such setup can be found on the attached picture, where you can see a Flash Click board, a FRAM one and our Quail board with an onboard 8MB Flash chip.
Then, code like the following code can be used :
public static void Main()
{
_storage1 = new OnboardFlash();
_storage2 = new FlashClick(Hardware.SocketOne);
_storage3 = new FRAMClick(Hardware.SocketTwo);
_storage1.WriteByte(10,value);
var _otherValue = _storage2.ReadByte(20);
var _tfs = new TFS(_storage3);
if (tfs.Exists("settings.dat")) { Debug.Print ("File found"); }
Thread.Sleep(Timeout.Infinite);
}
This has had some implications on the MBN Core assembly and the different “memory devices” drivers (EEprom, Flash, FRAM, Onboard Flash).
Onboard Flash is not a internal static class anymore but rather a single driver like any other. So if you do not need Onboard Flash support, then it will save you some memory for your program.
All this has made MBN Core assembly to change its version from 2.0 to 2.1. All the download links are now updated and we recommend you to switch to this new revision.
(*) TinyFileSystem (TFS) driver has been heavily modified by MBN but credits for the original driver go to Chris Taylor (Taylorza).