Main Site Documentation

Cobra II - Cannot Read from SDCard


#1

I am having problems reading a file from the SDCard on my Cobra II board. The SDCard is a standard SanDisk 1.0 GB card formatted with FAT32 4096. I have tried FAT 16 also.

The exception I’m getting is System.IO.IOException - CLR_E_FILE_IO (1). It occurs from a FileStream.Read and from a ReadByte. I’m using the PersistentStorage class.

It doesn’t seem to matter whether I create the file on the PC or from my GHI code. If I create the file in code (Create, Write), I can read it just fine. But if I unmount the SDCard, then mount it and try to read, it fails. I’m assuming that the Create/Write does not physically write the file to the SDCard whereas the unmount does.

Within the FileInfo collection the file is there with all the correct properties (CanRead, Length, etc.).

Here is the code. It’s pretty much right from the example:


    private void ReadFile(String FileName)
    {
        String RootDirectory = VolumeInfo.GetVolumes()[0].RootDirectory;
        FileStream FlashFile = new FileStream(RootDirectory + @ "\" + FileName, FileMode.Open, FileAccess.Read);
        Byte[] Data = new Byte[FlashFile.Length];
        FlashFile.Read(Data, 0, Data.Length);
    }


#2

@ MarkF -

Once Unmounted() is called. If you want to re-mount again, call ps.Dispose() (PersistentStorage ).

It also means you need to create new PersistentStorage again.


#3

Same behavior, IO Exception on Read :frowning:


#4

@ MarkF - Use a try {} catch(IOException) and watch the ioexception error code is set


#5

You are trying to read the entire file in one operation. There might be a size issue. Try reading the file in smaller chunks.