I am working on a project that requires an SD card because we have a lot of text files (that can’t be stored in the Cerberus’ memory.
The problem is that sometimes reading a file works and sometimes it doesn’t.
I can’t seem to find a pattern but sometimes the program starts to run fine. Other times I get “memory allocation failure” (with the number of blocks failed) and other times I get an IOException when FileStream.Read(data, offset, length) is called.
I have tried creating a test project which only mounts the SD card, prints out the root files and then reads one of them. This again sometimes works and sometimes doesn’t work.
I am using a powered USB hub and a Cerberus.
I have tried multiple SD cards and SD card modules as well as a couple of different Cerberus’ and microUSB cables.
Here is my (simple) code:
FileStream stream = storageDevice.OpenRead(fileName); byte data = new byte[stream.Length]; stream.Read(data, 0, data.Length); string returnString = new string(System.Text.Encoding.UTF8.GetChars(data)); stream.Close();
I have also tried using stream.ReadByte() thinking Read() might be the problem, but this made no difference.