Lecture Carte SD

French

Bonjour,
sur fez Hydra la lecture d’un fichier sur carte SD me provoque une erreur,

#### Exception System.IO.IOException - CLR_E_FILE_IO (1) ####
#### Message: 
#### Microsoft.SPOT.IO.NativeFileStream::Read [IP: 0000] ####
#### System.IO.FileStream::Read [IP: 0028] ####
#### Gadgeteer.Modules.GHIElectronics.Music::PlayBackStreamThreadFunction [IP: 0091] ####
#### Gadgeteer.Modules.GHIElectronics.Music::Play [IP: 0010] ####
#### Gadgeteertest.Program::sdCard_SDCardMountedmusic [IP: 0042] ####
#### Gadgeteer.Modules.GHIElectronics.SDCard::OnSDCardMountedEvent [IP: 004f] ####
#### System.Reflection.MethodBase::Invoke [IP: 0000] ####
#### Gadgeteer.Program::DoOperation [IP: 001a] ####
#### Microsoft.SPOT.Dispatcher::PushFrameImpl [IP: 004a] ####
#### Microsoft.SPOT.Dispatcher::PushFrame [IP: 001d] ####
#### Microsoft.SPOT.Dispatcher::Run [IP: 0006] ####
#### Gadgeteer.Program::Run [IP: 001c] ####
#### Gadgeteertest.Program::Main [IP: 001a] ####

Une exception de première chance de type ‘System.IO.IOException’ s’est produite dans Microsoft.SPOT.IO.dll
Error invoking method “Gadgeteer.Modules.GHIElectronics.SDCard” (check arguments to Program.BeginInvoke are correct)

J’ai changer le formatage de la carte SD Fat32, avec essai de plusieurs taille de Cluster :

La lecture du fichier sarrête a la taille du Cluster,
Cluster de 4 Ko => Lecture 4 Ko puis erreur…
Cluster de 8 ko => Lecture 8 Ko, puis erreur de lecture…

Je doit attendre une Mise a Jour ?

Pourriez-vous poster quelques exemples de code afin que nous puissions voir ce que vous faites?

Je m’excuse pour le mauvais français. J’ai utilisé un traducteur.

Voici une portion de code
Lecture de fichiers MP3 sur Module SD Card vers Module Music GHI Electronics


    /// A Music module for Microsoft .NET Gadgeteer
    /// 
    /// Original source from:
    /// http://gadgeteer.codeplex.com/SourceControl/changeset/view/14634


        /// <summary>
        /// Playback stream thread function
        /// </summary>
        private void PlayBackStreamThreadFunction(Stream file )
        {
            byte[] block = new byte[1024];
            m_SPI.Config = m_dataConfig;
            int Nboctet = 0;
            int total = 0;

            while ( (Nboctet = file.Read(block, 0, block.Length)) > 0)
            {

                total += Nboctet;

                Debug.Print("Lecture de : " + total.ToString() + " Octets ");

                if (_stopPlayingRequested) break;

                while (m_dreq.Read() == false)
                    Thread.Sleep(1);  // wait till done

                // fake spinlock is fake
                while (true)
                {
                    if (!m_bPlayLocked)
                    {
                        //someone still has the spi
                        Thread.Sleep(1);
                    }
                    else
                    {
                        // we can have the spi back
                        m_SPI.Config = m_dataConfig;
                        break;
                    }
                }

                m_SPI.Write(block);
            }

            if (file != null)
            {
                file.Close();
                file = null;
            }
            Reset();
            _isPlaying = false;
            this.OnMusicFinished(this);
        }

You will receive better support if you use English please.

Avez-vous entrer dans le code afin de déterminer à quelle ligne l’exception est levée? Traduction de courtoisie de Google Translate.

Analyse débogage:


Debug.Print("Lecture de : " + total.ToString() + " Octets ");

Affiche sur écran du PC
"Lecture de : 65536 Octets"
Envoie des donnée a la carte Music.
nouvelle boucle de lecture carte SD


 while ( (Nboctet = file.Read(block, 0, block.Length)) > 0)
    #### Exception System.IO.IOException - CLR_E_FILE_IO (1) ####

Bonjour Dav

Il faut essayer de faire un effort de traduction et de clarification du probleme. Nous continuons donc en anglais pour que la majorité de la communauté puisse un jour réutiliser ce thread.

If I were you I would try with an other SD card. Be sure also of your power supply most troubles with sd card comes from bad compatibility of the SDCARD with GHI modules or Bad power sources.

Have you written this code or is it a code that you found somewhere else?

Google translation
I will try with an additional power, then with another SD card
My problem, I format my sd card with 1 KB cluster, an exception is thrown after reading a KB, I formatted with cluster of 8 KB, the exception is raised after the reading of 8 KB
I can not read files greater than the size of the cluster.
I can enchainer reading several files, if they are less than a maximun size of clusters.
Formatting for SEVEN, Fat32 …
My code comes from:

http://gadgeteer.codeplex.com/SourceControl/changeset/view/14634#165134

Add code and mods to see the error, the original does not work …

As I do not have gadgeeter, I can’t try the code you find on codeplex. On all the FEZ target that I have I don’t take care about clustering. I buy an µSD CARD, I plug it in the slot, and that’s it. I can not say that I have no problem with SD (sometimes an SD card that is compatible with a given board will not work on a sisterchip FEZ based board)…

The first thinig try is to change SD card to see if SD is OK or not (some of them are created noise on power source…) then if changing SD does not solve the issue, changing the power module with a better one (if possible). In parralel the FEZ community that have time and the same target should try your code to see if the same problem occurs.

problem solved
I changed the SD card, and I have no problem reading
Thank you for your help

You’re welcome :slight_smile: