Main Site Documentation

SD Card troubles


#1

Hi all,

I’m starting a project that requires the SD Card module, I’ve used it fine in the past but for some reason it is now giving me some trouble.

I have a cerberus and the SD Card module attached to socket 7.

Currently I’m just trying to get a list of files from a directory but this isn’t working, I keep getting System.IO.IOException (directory not found).

Here is my Mounted event handler:

void sdCard_SDCardMounted(SDCard sender, GT.StorageDevice SDCard)
{
string[] directories = SDCard.ListRootDirectorySubdirectories();

        Debug.Print(directories.ToStrings());

        string[] subDirectories = SDCard.ListFiles(SDCard.RootDirectory + @ "\" + directories[0]);

        Debug.Print(subDirectories.ToStrings());
    }

(I have written the .ToStrings() method as an extension to string[] and it just prints each string on a newline).

For some reason, SDCard.ListRootDirectorySubdirectories() works but SDCard.ListFiles(SDCard.RootDirectory + directories[0]) does not. I’m following the way it is dont on the SD Card Module tutorial here (https://www.ghielectronics.com/docs/96/sd-card-module).

Does anyone know why this isn’t working?

Thanks for your time.

P.S. The card is FAT and I know it is being read because I can print the string[] returned from SDCard.ListRootDirectorySubdirectories();


#2

It just prints the folder names off, each on a new line.

Tom


#3

it would help if you explained “not working”. exactly what is happening?


#4

Sorry my fault, I thought you meant, what’s in the string array (read it wrong).

Let me try now.


#5

It prints out:

By not working I mean what I say in my original post, it just gives me a System.IO.Exception and if I catch it the Message is ‘file not found’ or ‘directory not found’ depending on if I use GetDirectories() or GetFiles().


#6

Still getting the same error if I do that.

I’ve tried another SD card as well now just in case that was the problem (although it gets the root directories so it doesn’t seem like it should).

[em]As a side note, the e.Message doesn’t print in Debug.Print which seems to be an bug, even if I force a ToString() on it.[/em]


#7

I just tried using another SD Card module and cable just in case it was that but I’m getting the same System.IO.IOException.


#8

How are you paying the board? Maybe power issue?


#9

I assume with Pesos, but being made in USA it only accepts dollars.


#10

@ Architect - lol


#11

Haha, I am powering it with the USB cable as normal but I remember in the past this working fine (although I was using the module with a spider not a cerberus).

If I can get a list of root directory files and directories, is it a power issue? It’s able to get those, but just not if I ask for the files and directories in any other directory.


#12

(I need to stop using my phone to answer question here! ) ::slight_smile:

Anything is possible when power is not sufficient. Using powered hub is much better and it also protects your PC.


#13

Your line

string[] subDirectories = SDCard.ListFiles(SDCard.RootDirectory + @ "\" + directories[0]);

should not have SDCard.RootDirectory + “” in it. ListFiles expects a path without the root. You just need to pass in the directories returned by ListDirectories directly, like

string[] subDirectories = SDCard.ListFiles(directories[0]);

#14

Ah thanks that works!!

Looking at the tutorial it made me think I needed SDCard.RootDirectory put at the start of the path string, thanks everyone for the help and I’m glad to have it working now :smiley: