The Netduino Plus has an on-board SD-card slot. It is connected to one of the SPI ports of the microcontroller. Fortunately, you don't need to write code to control the SPI port yourself. The firmware handles this for you, so all you need to do is work with the classes from the System.IO namespace. Do remember that this is the Micro .NET framework and it is not as rich as the full .NET framework, but it does provide enough implementation for working with the SD card.
The root of the file system on the SD card is '\SD'. So, to get all the files in the root directory, you could do the following:
[code:c#;ln:off;alt:on]string[] fileNames = Directory.GetFiles(@"\SD");[/code]
And anything else is just as simple as that. Below is an example that shows all folders and files on the card. You'll need to add a using statement for the System.IO namespace.
[code:c#;ln:off;alt:on]public class Program
{
public static void Main()
{
DirectoryInfo rootDirectory = new DirectoryInfo(@"\SD\");
RecurseFolders(rootDirectory);
}
private static void RecurseFolders(DirectoryInfo directory)
{
if (directory.Exists)
{
Debug.Print(directory.FullName);
foreach (FileInfo file in directory.GetFiles())
{
Debug.Print(file.FullName);
}
foreach (DirectoryInfo subDirectory in directory.GetDirectories())
{
RecurseFolders(subDirectory);
}
}
}
}
[/code]
If there is no card in the SD slot, the \'SD' directory will not exist. So check the Exist property before using the rest of the DirectoryInfo object. Using the object (other than the Exist property) if the directory it represents does not exist will throw an expection. If a DirectoryInfo object was already created, for an existing directory, and then the SD card is removed, an exception is thrown when accessing the object. Since removing a card is easy, you should write code that handles that possibility.
Oh, and do remember that the maximum SD card size the Netduino Plus can handle is 2GB. It is clearly mentioned on the Netduino Plus specifications page, but I overlooked it at first myself. When using a larger SD card, it will look as if no card has been inserted at all.
Next: communicate using RS232.