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.
Photo

SD card trouble


  • Please log in to reply
2 replies to this topic

#1 Sayril

Sayril

    New Member

  • Members
  • Pip
  • 1 posts

Posted 25 July 2012 - 12:51 AM

Hello everyone, I am very new to the whole Netduino thing, and I've been trying to get this 2GB Sandisk SD card that I got to work. I've tried countless codes, but nothing seems to work. I'm using firmware version 4.1.0.5. The SD card is formatted to FAT, and I have tried different firmware for the board. When I use
Directory.GetCurrentDirectory();
it just returns "\". If I try to write to the SD card, I get "An unhandled exception of type 'System.IO.IOException' occurred in System.IO.dll". The code I used is :
using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using Microsoft.SPOT.IO;
using SecretLabs.NETMF.Hardware.NetduinoPlus;
using System.IO;
using System.Text;

namespace NetduinoPlusApplication1
{
    public class Program
    {

        public static void Main()
        {
            FileStream fs = new FileStream("\\SD\\test.txt", FileMode.Create, FileAccess.ReadWrite, FileShare.None);
            StreamWriter sw = new StreamWriter(fs);
            sw.WriteLine("Hello World!");
            sw.Close();
            fs.Close();

        }
       
     }
    
}
Am I missing something really obvious here?

Thanks in advance.

#2 Nobby

Nobby

    Advanced Member

  • Members
  • PipPipPip
  • 70 posts

Posted 25 July 2012 - 08:20 AM

Your file creation and streamwriter code looks fine. The code will throw an exception though if

  • The file test.txt already exists on the SD card
  • The name of the root directory isn't \SD\

It may seem long-winded but I always query

VolumeInfo[] drives = VolumeInfo.GetVolumes();

It serves to ensure there is an SD card inserted(there are also other ways to check this). The objects also indicate the name of the root directory.

I haven't looked up the reference to Directory.GetCurrentDirectory for Micro Framework. It's standard usage is to return the current working directory which only applies to application domains running normal .Net Framework applications on a PC etc. Since the Netduino executes code from Flash rather than a virtualised application domain run from media, it doesn't use working directories.

#3 stotech

stotech

    Advanced Member

  • Members
  • PipPipPip
  • 143 posts
  • LocationAustralia

Posted 13 August 2012 - 09:45 AM

I've got a another SD card problem that I've posted over on another thread. http://forums.netdui...h__1#entry30966 I probably should have had posted here though. Any help would be appreciated. Thanks




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

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.