I’m trying to figure out how to use the micro-SD card with the Spider board. I’m pretty sure the problem is I’m missing a using statement and/or assembly reference but can’t figure out what I’m missing. I’ve included references to GHI.Premium.IO, Microsoft.SPOT.IO, Microsoft.SPOT.Native and mscorlib. My code is below.
Maybe a more important question is how do I figure out what using and assemblies I need for the hardware I’m using without having to resort to this forum?
using System;
using System.IO;
using System.Text;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.IO;
using GHI.Premium.IO;
namespace SDCardTest
{
public class Program
{
public static void Main()
{
Debug.Print(" Program Started \r\n");
PersistentStorage sCard = new PersistentStorage("SD");
sdCard.MountSDCard();
// sdCard.UnmountSDCard();
//Get the root directory
string rootDirectory = sdCard.GetStorageDevice().RootDirectory;
//Use Streamwriter to write a text file
StreamWriter textFile = new StreamWriter(rootDirectory + @ "\hello.txt");
textFile.WriteLine("Hello SD card");
textFile.Close();
//Use FileStream to read a text file
FileStream fileStream = new FileStream(rootDirectory + @ "\hello.txt", FileMode.Open);
//load the data from the stream
byte[] data = new byte[fileStream.Length];
fileStream.Read(data, 0, data.Length);
fileStream.Close();
string text = new string(Encoding.UTF8.GetChars(data));
Debug.Print(text);
}
}
}