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

Micro SD I/O Problems

sd microsd i/o

  • Please log in to reply
14 replies to this topic

#1 MadGeometer

MadGeometer

    New Member

  • Members
  • Pip
  • 2 posts

Posted 29 December 2012 - 06:28 AM

Can someone point to an example of doing I/O with the microSD card on Netduino Plus 2? Each and every example I tried (from this forum, from Google search results, etc.) always terminates with messages such as 

 

 

[font="'courier new', courier, monospace;"]A first chance exception of type 'System.NotSupportedException' occurred in Microsoft.SPOT.IO.dll[/font]
[font="'courier new', courier, monospace;"]A first chance exception of type 'System.NotSupportedException' occurred in System.IO.dll[/font]
[font="'courier new', courier, monospace;"]An unhandled exception of type 'System.NotSupportedException' occurred in System.IO.dll[/font]
(when using StreamWriter or StreamReader)
 

or (when using DirectoryInfo):

[font="'courier new', courier, monospace;"]A first chance exception of type 'System.IO.IOException' occurred in Microsoft.SPOT.IO.dll[/font]

 

All references are to 4.2.0.0 assemblies (except for SecretLabs.NETMF.Hardware.NetduinoPlus which is at 4.2.0.1). 

 

Any help would be greatly appreciated!

 

 

 

 

 

 



#2 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 29 December 2012 - 11:26 AM

you need the SecretLabs.NETMF.Hardware.Netduino reference for the plus2, not the plus one.

 

thats a simple sd sample.

 

static String logDirectory = @"SDLogs";        public void Log(String Text)        {            lock (lockObj)            {                using (StreamWriter writer = new StreamWriter(logDirectory + "log.txt", true))                {                    writer.WriteLine(DateTime.Now + ": " + Text);                }            }        }

 



#3 MadGeometer

MadGeometer

    New Member

  • Members
  • Pip
  • 2 posts

Posted 31 December 2012 - 06:06 AM

Hi NooM, 

 

Thanks for your response, but this is the output:

 

A first chance exception of type 'System.NotSupportedException' occurred in Microsoft.SPOT.IO.dll
A first chance exception of type 'System.NotSupportedException' occurred in System.IO.dll
An unhandled exception of type 'System.NotSupportedException' occurred in System.IO.dll
 
Any ideas?
 
Here's the code I'm using:
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;
 
namespace MicroSD_Card_Writer_Example
{
    public class Program
    {
        static String rootDirectory = @"SD";
 
        public static void Main()
        {
            Program pgrm = new Program();
            pgrm.Log("Hello, world!");
        }
 
        public void Log(String Text)
        {
            lock (this)
            {
                using (StreamWriter writer = new StreamWriter(rootDirectory + "log.txt", true))
                {
                    writer.WriteLine(DateTime.Now + ": " + Text);
                }
            }
        }
    }
}
 

References listed in Visual C# 2010 Express are the defaults for the Netduino Plus 2 template, along with System.IO (required because of the StreamWriter):

Microsoft.SPOT.Hardware (Version 4.2.0.0)

Microsoft.SPOT.Hardware.PWM (Version 4.2.0.1)

Microsoft.SPOT.Hardware.SerialPort (Version 4.2.0.0)

Microsoft.SPOT.Hardware.Native (Version 4.2.0.0)

Microsoft.SPOT.Hardware.Net (Version 4.2.0.0)

mscorlib (Version 4.2.0.0)

SecretLabs.NETMF.Hardware (Version 4.2.0.0)

SecretLabs.NETMF.Hardware.Netduino (Version 4.2.1.0)

System (Version 4.2.0.0)

System.IO (Version 4.2.0.0)



#4 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 31 December 2012 - 09:45 AM

sry idk, it should work.

maybe try adding secretlabs.netmf.io (but thats not needed ni think, theres the class to mount the card, wich should do automatically)

 

it can also be the duino cant read your card, is it 2gb and foratted correctl?



#5 Nevyn

Nevyn

    Advanced Member

  • Members
  • PipPipPip
  • 1072 posts
  • LocationNorth Yorkshire, UK

Posted 31 December 2012 - 10:50 AM

Any ideas?

 
Here's the code I'm using:

 

I've just pasted MadGeometer's code into a new N+2 project and compiled and run this OK.  The app create a new log file with the expected text in the file.  The references/DLLs in the project are the same as you have quoted.

 

I'm using a SanDisk 1GB microSD card formatted with a FAT file system.  If memory serves, most cards 2GB or under should work and some cards above 2GB have been found to be working.

 

Regards,

Mark


To be or not to be = 0xFF

 

Blogging about Netduino, .NET, STM8S and STM32 and generally waffling on about life

Follow @nevynuk on Twitter


#6 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 31 December 2012 - 12:48 PM

I wonder if it is crashing on the DateTime.Now. Where are you setting the Date/Time? If this is a null it could crash it.
 

EDIT:

I just tried the project here with multiple brands of 2gig SD Cards and it worked fine on all.

 

On all without setting the time it logged the following:

 

06/01/2011 00:01:18: Hello, world!

 

 

Can you zip up the project and post it.  Maybe there is another setting at fault and we can check it.


Edited by Dave VanderWekke, 31 December 2012 - 01:01 PM.


#7 Nevyn

Nevyn

    Advanced Member

  • Members
  • PipPipPip
  • 1072 posts
  • LocationNorth Yorkshire, UK

Posted 31 December 2012 - 12:58 PM

Dave,

 

 

I wonder if it is crashing on the DateTime.Now. Where are you setting the Date/Time? If this is a null it could crash it.

 

If this were null then I would expect this to throw a "Object not set to and instance..." type exception.

 

The DateTime.Now should reference a static member set up by the .NET run-time system.  You do not have to initialise this, it's just there for you when you first need it.

 

Regards,

Mark


To be or not to be = 0xFF

 

Blogging about Netduino, .NET, STM8S and STM32 and generally waffling on about life

Follow @nevynuk on Twitter


#8 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 31 December 2012 - 01:22 PM

iam using a rtc to get the date/time for my logfiles.

 

else it starts with zero everytime power is off :(



#9 JohnGuin

JohnGuin

    New Member

  • Members
  • Pip
  • 8 posts
  • LocationRedmond WA

Posted 01 January 2013 - 04:48 AM

I am getting the exact same erorrs using the exaxt same code as noom.  Sandisk 8GB card, formatted to fat32.  The card works fine in other devices.

 

Anything else needed to help with this?



#10 Arron Chapman

Arron Chapman

    Advanced Member

  • Members
  • PipPipPip
  • 289 posts
  • LocationOregon, USA

Posted 01 January 2013 - 05:18 AM

I am getting the exact same erorrs using the exaxt same code as noom.  Sandisk 8GB card, formatted to fat32.  The card works fine in other devices.

 

Anything else needed to help with this?

 

Most cards above 4GB are unlikely to work.  As far as I know, 4GB cards are hit and miss, and most anything 2GB or smaller should work fine.


When you talk EE use small words, I'm just a Software Developer :)
My Blog/Site and Everything Else

If my post helped you please consider pressing the "Like This" button in the bottom right-hand corner.

 

Oh my. So many things, so little money!!

 


#11 JohnGuin

JohnGuin

    New Member

  • Members
  • Pip
  • 8 posts
  • LocationRedmond WA

Posted 01 January 2013 - 05:20 AM

OK, thanks.  I'll see if I can dig up a smaller card and will try again.



#12 JohnGuin

JohnGuin

    New Member

  • Members
  • Pip
  • 8 posts
  • LocationRedmond WA

Posted 02 January 2013 - 04:36 AM

To follow up, downgrading to a 2GB card works like a champ.  Thanks for the help!



#13 Arron Chapman

Arron Chapman

    Advanced Member

  • Members
  • PipPipPip
  • 289 posts
  • LocationOregon, USA

Posted 02 January 2013 - 06:58 PM

To follow up, downgrading to a 2GB card works like a champ.  Thanks for the help!

 

If one of the answers helped you, please hit the "Mark Solved" button in the lower right hand cornor of the post.


When you talk EE use small words, I'm just a Software Developer :)
My Blog/Site and Everything Else

If my post helped you please consider pressing the "Like This" button in the bottom right-hand corner.

 

Oh my. So many things, so little money!!

 


#14 Jack Chidley

Jack Chidley

    Advanced Member

  • Members
  • PipPipPip
  • 99 posts

Posted 30 June 2013 - 05:29 PM

I've tried this.  Doesn't work for me.  Using NETMF 4.3 Netduino Plus 2.  VS 2012, Windows 8 64bit.  References System.IO, Microsoft.SPOT.IO and SecretLabs.NETMF.IO.  Using a SanDisk 1Gb and 2Gb cards.

 

Code works fine on a Netduino Plus 1.  Same setup, same cards.

 

Downgraded to 4.2.2.2.  Same issue on N2+.

 

Occasionally works if left for a looooong time.  No consistent pattern.


Edited by Jack Chidley, 30 June 2013 - 06:32 PM.


#15 pajtimi

pajtimi

    New Member

  • Members
  • Pip
  • 2 posts

Posted 29 September 2013 - 12:49 PM

I've tried this.  Doesn't work for me.  Using NETMF 4.3 Netduino Plus 2.  VS 2012, Windows 8 64bit.  References System.IO, Microsoft.SPOT.IO and SecretLabs.NETMF.IO.  Using a SanDisk 1Gb and 2Gb cards.

 

Code works fine on a Netduino Plus 1.  Same setup, same cards.

 

Downgraded to 4.2.2.2.  Same issue on N2+.

 

Occasionally works if left for a looooong time.  No consistent pattern.

This is true but can we have any solution for this issue?







Also tagged with one or more of these keywords: sd, microsd, i/o

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.