I added SecretLabs.NETMF.IO.dll and System.IO as references in my project and then put this code in my Netduino app's Program.cs file. It simply mounts the SD card, gets a directory listing, and then prints out both the list of directories and the contents of the SD1 folder.
using System.IO; using SecretLabs.NETMF.IO; // ... public static void Main() { StorageDevice.MountSD("SD1", SPI_Devices.SPI1, Pins.GPIO_PIN_D10); string[] directories = System.IO.Directory.GetDirectories(@"\"); Debug.Print("directory count: " + directories.Length.ToString()); for (int i = 0; i < directories.Length; i++) { Debug.Print("directory: " + directories[i]); } string[] files = System.IO.Directory.GetFiles(@"\SD1"); Debug.Print("file count: " + files.Length.ToString()); for (int i = 0; i < files.Length; i++) { Debug.Print("filename: " + files[i]); FileStream fs = new FileStream(files[i], FileMode.Open, FileAccess.Read, FileShare.None, 512); StreamReader sr = new StreamReader(fs); Debug.Print("contents: " + sr.ReadToEnd()); } }
Three notes:
1. The current alpha release ignores all parameters except for the first parameter (the target mounting folder). We'll be enabling support of different chip select lines and also an auto-mounting feature in an alpha/beta release next week.
2. You must use SD cards which support SPI. SDHC cards are not supported at this time. So I'd recommend SD cards that are <=2GB. I'm using a Kingston 2GB MicroSD cards in a MicroSD->SD adapter in this sample project.
3. I'm using StreamReader.ReadToEnd() here. That will only work with small files (as it reads the entire file into memory), and is just used as a simple example. If you would like to read/write large files, you'll want to read/write small chunks of data instead.
Enjoy!
Chris