Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.

MosziNet

Member Since 06 Oct 2011
Offline Last Active Oct 01 2015 12:59 PM
-----

#19774 SD card sample

Posted by MosziNet on 25 October 2011 - 09:22 PM

An other sample, that may be relevant to using the SD card.


using System;
using Microsoft.SPOT;
using Microsoft.SPOT.IO;
using System.IO;

namespace Moszi.Net.Duino.WebServer
{
    /// <summary>
    /// The <see cref="FileManager"/> class is responsible of creating the profile file names based on the Netduino SD card name.
    /// </summary>
    public static class FileManager
    {
        private static bool hasFileSystemSupport;
        private static string rootFolderName; 

        /// <summary>
        /// Sets up the file manager class.
        /// </summary>
        static FileManager()
        {
            // find all volumes 
            VolumeInfo[] volumes = VolumeInfo.GetVolumes();
            foreach (var volumeInfo in volumes)
            {
                // then search for the sd card volume
                if (volumeInfo.Name == Constants.SDCardName)
                {
                    // check if the volume is formatted, if not then we can't use this
                    if (!volumeInfo.IsFormatted)
                    {
                        break;
                    }

                    // build the root folder name, and set our file system support flag to true
                    rootFolderName = Path.Combine( "\\" + volumeInfo.Name, Constants.HomeControllerFolder);

                    // create the directory if it doesn't exist
                    if (!Directory.Exists(rootFolderName))
                    {
                        Directory.CreateDirectory(rootFolderName);
                    }

                    hasFileSystemSupport = true;
                }
            }
        }

        private static string RootFolderName
        {
            get
            {
                return rootFolderName;
            }
        }

        /// <summary>
        /// Returns whether there is file system support in this HomeController.
        /// </summary>
        public static bool HasFileSystemSupport
        {
            get
            {
                return hasFileSystemSupport;
            }
        }

        /// <summary>
        /// Returns the filename for the password.
        /// </summary>
        public static string PasswordFilename
        {
            get
            {
                // build and return the 
                return Path.Combine(RootFolderName, Constants.HomeControllerPassword);
            }
        }
    }
}

The example uses the following constants:

        /// <summary>
        /// The name of the volume where Netduino can save information. Change this to SD if you are using
        /// a real NetDuino device, or change it to WINFS if you are using the emulator.
        /// </summary>
        public const string SDCardName = @"SD";

        /// <summary>
        /// The folder where Netduino stores information.
        /// </summary>
        public const string HomeControllerFolder = "DuinoWebServer";

        /// <summary>
        /// The password file name.
        /// </summary>
        public const string NetDuinoPassword = "password.txt";



home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.