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

Write to SD Card


Best Answer Kip, 26 February 2014 - 01:01 PM

Netduino doesn't support SDHCs, just plain old SDs ;)

Go to the full post


  • Please log in to reply
7 replies to this topic

#1 NoxiaZ

NoxiaZ

    Member

  • Members
  • PipPip
  • 12 posts

Posted 25 February 2014 - 10:58 AM

Hey,

 

Im using framework 4.3 and trying to write to an SD card, but gives me an error:

 

An unhandled exception of type 'System.NotSupportedException' occurred in System.IO.dll

 

on this line:

 

Stream st = new FileStream(@"SDtest.txt", FileMode.OpenOrCreate);

 

Whats wrong? :S



#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 26 February 2014 - 01:36 AM

Hi NoxiaZ, First thing...please add a "" before "SD", making it "SD". Beyond that: is your Netduino Plus 2 detecting the SD card (i.e. you see a "SD" folder when you do GetDirectories on @"")? Can you see the files on the SD card using GetFiles? The SD code in 4.3.1 should be identical to 4.2.2.2. We ran our standard SD card tests (from our test jigs) on the firmware before posting it...so the basic SD functionality at minimum is working in the firmware. Chris

#3 NoxiaZ

NoxiaZ

    Member

  • Members
  • PipPip
  • 12 posts

Posted 26 February 2014 - 10:53 AM

Hi Chris,

 

i have tried everything nearly for writing.

 

  try
  {
  string[] directories = Directory.GetDirectories("");
  string dir = "";
  Debug.Print("Directories count: " + directories.Length);
  for (int i = 0; i < directories.Length; i++)
  {
  Debug.Print("Directory: " + directories[i]);
  if (directories[i].ToLower().IndexOf("sd") >= 0)
  {
  dir = directories[i];
  Debug.Print("Found: " + dir);
  }
  }

  Debug.Print("Finding files");
  string[] files = Directory.GetFiles(dir);
  Debug.Print("File count: " + files.Length);
  for (int i = 0; i < directories.Length; i++)
  {
  Debug.Print("Files: " + files[i]);
  }

  Stream st = new FileStream(dir + @"Log.txt", FileMode.OpenOrCreate);
  }
  catch (Exception ex)
  {
  Debug.Print("Error: " + ex);
  }

 

And this is the log:

 

Directories count: 1
Directory: SD
Found: SD
Finding files
A first chance exception of type 'System.NotSupportedException' occurred in Microsoft.SPOT.IO.dll
A first chance exception of type 'System.IO.IOException' occurred in System.IO.dll
Error: System.IO.IOException



#4 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 26 February 2014 - 11:21 AM

Hi NoxiaZ, Please try reformatting your card on your PC. BTW, what size is the card? <=2GB? Or a larger SDHC card? Chris

#5 NoxiaZ

NoxiaZ

    Member

  • Members
  • PipPip
  • 12 posts

Posted 26 February 2014 - 11:48 AM

I just reformatting it, and its a SDHC 8GB - Is that a problem? :/



#6 Kip

Kip

    Member

  • Members
  • PipPip
  • 22 posts
  • LocationItaly

Posted 26 February 2014 - 01:01 PM   Best Answer

Netduino doesn't support SDHCs, just plain old SDs ;)



#7 NoxiaZ

NoxiaZ

    Member

  • Members
  • PipPip
  • 12 posts

Posted 26 February 2014 - 01:15 PM

Ohh :(

 

And thanks for you answer ;)



#8 RayHAz

RayHAz

    New Member

  • Members
  • Pip
  • 2 posts

Posted 20 March 2014 - 01:27 PM

Would be nice to have one central location where all the answers are laid out simply.  There's a lot of info out there, but it's scattered, and a lot of it is wrong (good-intentioned people who are coding and testing with bad results).  Here's what I think I know so far...

 

I'm using a Netduino Plus 2, programming in VB with Visual Studio 2013, but using MF 4.2 (not 4.3).  I've successfully written code to flash LED's, move servos, accept TCP/IP connections, etc.

 

Like most people, I thought just any old micro form-factor card would work.  I found a 2GB SD (non-SDHC) micro SanDisk card for under $6 (I added to my Amazon list here http://astore.amazon...ar01-20?&node=4 if you want a quick reference -- buy two, they're small!).

 

Per other suggestions, I formatted it on my PC (FAT, allocation unit size 32K, volume label "NetD-01", not quick-formatted).

 

I have the following simple code, taken from what appears to be several successful C# SD writing examples:

 

Try

   Using SW As New System.IO.StreamWriter("\SD\Test.txt")

       SW.WriteLine("This is a test!")

   End Using

Catch ex as Exception

   Debug.Print("Error writing to SD card: " & ex.Message)

End Try

 

THIS WORKS!  I removed the SD card, put it in my PC, and that file is present and readable!  You'll note that the Date Modified is not accurate unless you have something to set your Netduino's clock.

 

Note: At first I tried the StreamWriter to write simply to "Test.txt", but this threw an error.  Apparently you MUST include the full path.

 

I hope this helps anyone






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.