Main Site Documentation

GHIElectronics.NETMF.IO.dll 'System.Exception'


#1

Hi,

I am getting the following exception error when trying to detect or connect to any device USB/SD that is not connected. Which stops me from continuing with the rest of my application. I have tried to catch/throw the exception but It doesnt get caught and get a prompt from vs to break or continue.

I have also tried the PersistentStorage.DetectSDCard() which also throws the same error! I am using the GHIElectronics.NETMF.IO version 4.1.3.0

I have disabled the following on my debugger, but still crashed.
* Go to Tools/Options/Debugging and turn off “Enable Just My code (Managed only)”. or option.

* Go to Debugger/Exceptions and turn off "User-unhandled" for Common-Language Runtime Exceptions.

An unhandled exception of type ‘System.Exception’ occurred in GHIElectronics.NETMF.IO.dll


using System;
using System.Threading;
using System.IO;
using GHIElectronics.NETMF.IO;

namespace SD.Startup
{
    public static class SDCard
    { 
      private static PersistentStorage sd;

       public static void ConnectSD()
       {
         sd = new PersistentStorage("SD"); // Error thrown here.
          sd.MountFileSystem();
       }
    }
}

Has anyone elese come across the same thing?

Thank you
Nathan


#2

You can’t create the PersistentStorage(“SD”) object unless there IS a SD card inserted. Before creating the object make sure there is a SD card by using the PersistentStorage.DetectSDCard()


#3

Thanks Wouter,

I had tried the PersistentStorage.DetectSDCard() too which is meant to return a boolen, but that crashes too with the same error.

So a bit lost here


#4

try and catch should work fine. This is standard .NET C#.
DetectSDCard() method is not available on ChipworkX. If you want to detect the SD card, you have to connect the SD Detect pin to an InterruptPort on ChipworkX. There are other posts about this on the forum…


#5

Thanks Mike, I’ll give it a try.
No, the try catch doesnt work. I’ll try the detect pin.

Thanks

Yes the detect PIN worked. Thanks for your help everyone.


#6

Hi me again,

I am now getting alot of Microsoft.SPOT.IO.dll exceptions. That cannot be handled which terminates my application.

I have been trying to work with the sd card. But keep getting Microsoft.SPOT.IO.dll exceptions.

Detecting when a card is inserted works fine. Acessing the SD is where it starts crashing. I have formatted the card FAT 32 on my pc, but the chipwork board says its not. So, I try to format it using the volumeinfo class and format method but that crashes. I’ve tried another sd card, stripped my code to basic (below). Also, my system crashes when I use the UnmountFileSystem() function on my NAND or any hostusb.

I am getting the same problem as the person here http://www.ghielectronics.com/forum/index.php?topic=1679.0


using System;
using System.IO;
using System.Threading;
using Microsoft.SPOT;
using GHIElectronics.NETMF.IO;
namespace Test
{
class Program
{
public static void Main()
{

   PersistentStorage sdcard = new PersistentStorage("SD");
   sdcard.MountFileSystem();
   Microsoft.SPOT.IO.VolumeInfo[] AllVol =Microsoft.SPOT.IO.VolumeInfo.GetVolumes();

                if (!AllVol[1].IsFormatted)
                {
// quick check make sure I dont wipe my NAND!! //
                    if (AllVol[1].Name.ToUpper() == "SD")
                    {
                        AllVol[1].Format("FAT", 0, true); // Crash here
                    }
                }
}
}
}


Am I doing something wrong, or maybe it could be a hardware failure.

Thanks
Nathan


#7

I found that I needed to put a delay in either after declaring the PersistantStorage object or after mounting the file system (don’t remember which). It seems some cards can be a bit slow in responding.


#8

Thanks Jeff, that took care of the UnmountFileSystem() error.


#9

Please format the card on the PC using FAT32 and try the example in the ebook without any changes. Try another SD card if you have one.


#10

Hi Mike,

I have tried this already, but will try again. I’m not sure why the format option using the volumeinfo doest worked, that method worked fine on my nand.

Thanks

Ok, that never worked. I can detect the SD card. But for some reason not talk to it. I can read/write to the sd cards on my PC. hummm strange


#11

It may take some time to format because of SD card size…


#12

I dont get that far, it just crashes. I’m using a 512MB card.


#13

What do mean crashes? Exception?


#14

An unhandled exception of type ‘System.IO.IOException’ occurred in Microsoft.SPOT.IO.dll


I have attached an external SD card module through SPI2, and managed to detect a file exist on the card.

So, I either have a code issue or hardware issue on this board.


#15

You needed SD detect in previous post. Did you connect anything to SD card physically?


#16

Detect yes, but not able to read/write to it.


#17

Perhaps this example will help you.
We have no issues reading files:


using System;
using Microsoft.SPOT;
using System.Net;
using System.Threading;
using NetMf.CommonExtensions;
using System.IO;
using GHIElectronics.NETMF.IO;

namespace Arendee.Led.DeviceServer
{
    internal static class FileManager
    {
        static PersistentStorage sdCard;

        public static bool SDCardLoaded
        {
            get;
            set;
        }

        public static byte[] ReadFile(string filename)
        {
            byte[] data = null;

            if (sdCard == null)
            {
                try
                {
                    sdCard = new PersistentStorage("SD");
                    sdCard.MountFileSystem();
                    SDCardLoaded = true;
                }
                catch (Exception ex)
                {
                    Debug.Print("Failed to mount SD card: " + ex.Message);
                    SDCardLoaded = false;
                }
            }

            if (SDCardLoaded)
            {
                filename = filename.Replace("/", "\\");
                if (filename[0] == '\\') 
                    filename = filename.Substring(1);

                var path = Path.Combine("\\SD", filename);
                if (File.Exists(path))
                {
                    data = File.ReadAllBytes(path);
                }
                Thread.Sleep(200);
            }

            return data;
        }

        public static void UnmountSDCard()
        {
            if (SDCardLoaded)
            {
                sdCard.UnmountFileSystem();
                Thread.Sleep(200);
                sdCard.Dispose();
            }
        }

    }
}

#18

I’m having the same problem described in this post but I’m using Domino and the newest SDK. The SD card is formated, inserted before running the program. All dll referenced are from the same SDK. This is my code:


            Debug.Print("Please insert SD card...");

            while (!PersistentStorage.DetectSDCard())
                Thread.Sleep(1000);

            Debug.Print("SD card detected");

            try
            {
                using (var sd = new PersistentStorage("SD"))
                {
                    sd.MountFileSystem();

                    var volume = VolumeInfo.GetVolumes()[0];
                    
                    if (volume.IsFormatted)
                    {
                        Debug.Print(volume.RootDirectory);

                        foreach (var dir in Directory.GetDirectories(volume.RootDirectory))
                        {
                            Debug.Print(dir + "/");
                        }

                        foreach (var file in Directory.GetFiles(volume.RootDirectory))
                        {
                            Debug.Print(file);
                        }
                    }
                    else
                    {
                        Debug.Print("SD card not formatted");
                    }

                    sd.UnmountFileSystem();
                }
            }
            catch (Exception e)
            {
                Debug.Print(e.Message);
            }

And this is the result:


#19

It seems that my SD card is not compatible. I tried the same code with a 2GB card (Kingston SDC/2GB) and it works. My card however (Kingston SDC4/4GB) causes an exception. I read that PersistentStorage is able to use SD cards > 2GB (SD HC) so I assume something is wrong ? My card works on PC just fine.


#20

I found GUS post about Kingston SD HC cards:

Shame i didn’t know about that earlier :confused: If i add this extra capacitor will it work with other SD and SD HC cards ?