Jeroen Swart

.NET Architect

NetDuino - Getting Started with SD

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.

Windows Phone 7 and a Kerio mailserver

At work, we use a Kerio mailserver. To Windows Mobile and Windows Phone devices it looks like an Exchange Server, so you can add your account as an Outlook/Exchange account. Well, in theory. I tried this before, but wasn't able to add the account. I could create a POP3 account, but that left me with e-mail only, not my calendar.

Yesterday I tried again. With a colleague looking at the Kerio logging (thanks Sander!), we found why creating the Outlook/Exchange account on the phone was not working.

When creating the account you need to provide several settings, amongst which is the Domain. I simply assumed this should be the domain of the account (as in domain\username), like when connecting to a real Exchange server. Not so with Kerio. You need to provide the full domain of your e-mail address. So in the case of username@domain.com, the Domain setting should be domain.com.