Main Site Documentation

Cobra II SD-Card InvalidOperationException


#1

I would like to use the Interface to the SD-Card, but I don’t succeed.
Both the funtion in the …FEZCobraII namespace and in the GHI.Hardware.Storage namespace lead to the same result.

Code:
SDCard sd = new SDCard();

#### Exception System.InvalidOperationException - CLR_E_INVALID_OPERATION (1) ####
#### Message: 
#### GHI.IO.Storage.SDCard::NativeConstructor [IP: 0000] ####
#### GHI.IO.Storage.SDCard::.ctor [IP: 0017] ####
#### SDTestCobra.Program::ProgramStarted [IP: 000b] ####

What I’m doing wrong ?
What should I do best ?

thx a lot.

Michael


#2

Now, I use following code…


            Mainboard.SDCardMounted += Mainboard_SDCardMounted;
            Mainboard.SDCardUnmounted += Mainboard_SDCardUnmounted;

            Debug.Print("Program Started");

            if (Mainboard.IsSDCardInserted)
            {
                if (Mainboard.IsSDCardMounted)
                {
                    StorageDevice sd = Mainboard.SDCardStorageDevice;

                    if (sd.Volume.IsFormatted)
                    {
                        string rootDirectory = sd.RootDirectory;
                        string[] files = Directory.GetFiles(rootDirectory);
                        string[] folders = Directory.GetDirectories(rootDirectory);

                        Debug.Print("Files available on " + rootDirectory + ":");
                        for (int i = 0; i < files.Length; i++)
                            Debug.Print(files[i]);
                        Debug.Print("Folders available on " + rootDirectory + ":");
                        for (int i = 0; i < folders.Length; i++)
                            Debug.Print(folders[i]);

                    }

                }
            }

In this case I can read the content of the card. But the events for insert an remove the are not fired.

I will looking for the reason about this.
If someone knows about this can write a message.

Thx a lot.

Michael


#3

@ MHSchmidt - Which events are you referring to? Mainboard_SDCardMounted and Mainboard_SDCardUnmounted?


#4

Yes, I can insert and remove but nothing happens.
I expect that the function is called.

Thx.


#5

@ MHSchmidt - Are there other mass storage drives that you can try?


#6

Yes, I have tried it with USB.
The insert event is fired and worked fine, but when I remove the stick an exception occured.

see other post.

Thx.