FEZCerb-family and OSHW StorageDev

Hi everybody.

We’re making some tests on a FEZ-Cerbuino-Bee board and we’d like to try file-system support provided through StorageDev class of OSHW GHI assembly.

After having mounted SD, that seems to work, we get an empty array returned by VolumeInfo.GetVolumes() and a single string (“FAT”) returned by VolumeInfo.GetFileSystems().

Is it normal?

Is there any other intended use of such class?

Thanks!

@ Innovactive - Something like this?

using System;
using System.IO;
using Microsoft.SPOT.IO;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
 
namespace SD_Test
{
    public partial class Program
    {
        private GT.Timer _timer;
        private string _root;
 
        void ProgramStarted()
        {
            GHI.OSHW.Hardware.StorageDev.MountSD();
            if (VolumeInfo.GetVolumes()[0].IsFormatted)
            {
                _root = VolumeInfo.GetVolumes()[0].RootDirectory;
                _timer = new GT.Timer(5000);
                _timer.Tick += new GT.Timer.TickEventHandler(TimerTick);
                _timer.Start();
            }
        }
 
        void TimerTick(GT.Timer timer)
        {
            string fileName = Path.Combine(_root, "file.txt");
            Stream stream;
            if(File.Exists(fileName))
            {
                stream = File.OpenWrite(fileName);
                stream.Position = stream.Length;
            }
            else
            {
                stream = File.Create(fileName);
            }
            using(var writer = new StreamWriter(stream))
            {
                writer.WriteLine(Guid.NewGuid().ToString());
            }
            stream.Dispose();
        }
    }
}
1 Like

Just after having posted our question, our test app started working a little better, but not still “well”.

We’re using plain vanilla .NETMF, with something like this:


private static void testSD()
        {
            StorageDev.MountSD();

            var volumes=VolumeInfo.GetVolumes();
            var fs = VolumeInfo.GetFileSystems();

            if (volumes.Length == 0) return;

            var volume = volumes[0];

            var dir = volume.RootDirectory;

            foreach (var file in Directory.GetFiles(dir))
            {
                using(var sr=new StreamReader(File.OpenRead(file)))
                {
                    Debug.Print(sr.ReadToEnd());
                }
            }

            StorageDev.UnmountSD();
        }

But we get:

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
An unhandled exception of type ‘System.IO.IOException’ occurred in System.IO.dll

while calling “Directory.GetFiles(dir)”.

Any hints?

BTW, memory card we are working with is a 1Gb SanDisk microSD formatted as FAT.

@ Innovactive - The only Gadgeteerie os the timer in my example so you could take the timer fluff and put it in your testSD function

Other than that i cant test anything as my bee is at the office…

Try adding 200ms Sleep after mounting the card.

What is the HRESULT code inside the NotSupportedException?

http://www.tinyclr.com/codeshare/entry/218

We get:

HRESULT: CLR_E_DIRECTORY_NOT_FOUND

Actually “var dir = volume.RootDirectory;” returns “\SD” (of course watch shows double back slash, i.e. \SD), but enumerating files there fails.

We have a file on root, and a folder with a file inside.

What could be wrong?

(BTW, it seems that hresult cast to uint at line 138 of your class must be preceded by an intermediate cast to int, since Exception m_hresult property type is “int” and casting returned “object” (got by reflection) throws an invalidcastexception…)

@ Innovactive - tested and working on my bee

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

namespace SdTest
{
    public class Program
    {
        private static string _root;

        public static void Main()
        {
            GHI.OSHW.Hardware.StorageDev.MountSD();
            if (VolumeInfo.GetVolumes()[0].IsFormatted)
            {
                _root = VolumeInfo.GetVolumes()[0].RootDirectory;
            }
            foreach (var file in Directory.GetFiles(_root))
            {
                using (var sr = new StreamReader(File.OpenRead(file)))
                {
                    Debug.Print(sr.ReadToEnd());
                }
            }
            GHI.OSHW.Hardware.StorageDev.UnmountSD();
        }
    }
}

Thank you! Yeah I haven’t tested the helper on 4.2. Worked fine on 4.1 with no exceptions. I will update the code.

Try adding trailing "" to the root directory.

No, it doesn’t work…maybe it depends on working with a debug version of ghi porting we’ve working with? Other tests ran fine…

@ Innovactive - What firmware are you using?
Above code works fine on me bee with 4.2.3.1 non ethernet

4.2.3.0 Porting Kit “stock” solution.

@ Innovactive - Guess they must be different…