Main Site Documentation

SD Card file write takes forever to Close or Flush


#1

Hi, i’m playing with my SD Card module and having problem writing data to the card.

It takes forever to flush and I can’t seems to get the text file written.

Here’s my code


            sdCard.MountSDCard();
            sdCard.SDCardMounted += sdCard_SDCardMounted;
            sdCard.SDCardUnmounted += sdCard_SDCardUnmounted;

            VolumeInfo vi = sdCard.GetStorageDevice().Volume;
            Debug.Print(vi.Name);
            Debug.Print(vi.IsFormatted.ToString());
            Debug.Print(vi.FileSystem);
            Debug.Print(vi.TotalFreeSpace.ToString());

            string root = sdCard.GetStorageDevice().RootDirectory;
            Debug.Print("Root: " + root);


            var rootDirectory = sdCard.GetStorageDevice().RootDirectory;
            var textFile = new StreamWriter(rootDirectory + @ "\hello.txt");
            textFile.WriteLine("Hello SD card. " + DateTime.UtcNow.ToString());
            //textFile.Flush();
            textFile.Close();

            sdCard.UnmountSDCard();

Did i missed something obvious. I’m using FEZRaptor. NETMF 4.2


#2

Hi,
try to call a method like this after the command: textFile.close();

 
textFile.close();
FinalizeVolumes();
Thread.Sleep(100);

private void FinalizeVolumes()
        {
            VolumeInfo[] vi = VolumeInfo.GetVolumes();
            for (int i = 0; i < vi.Length; i++)
                vi[i].FlushAll();
        }
 

#3

@ RoSchmi, it works. Thanks.

NOTE: Notice the SD card that come with the purchase of the SD Card Module is kinda slow. It works way better after I replace with the Kingston class 4 SD Card. Not sure if it’s just my case of others are experiencing the same.


#4

You’re welcome.
What do you mean with slow? What is your datarate?


#5

I need to copy these code
:smiley:


#6

Too much honor, it’s not from me: