I’m having an issue with reading data from an SD card. Using EMX dev kit and 4.2 RC2.
This is the code:
//Load old data from SD card
if (File.Exists(rootDirectory + @ "\TempHumid.csv"))
{//load data
StreamReader FileReader = new StreamReader(rootDirectory + @ "\TempHumid.csv");
if (FileReader.BaseStream.Length > (35 * 800))
{
FileReader.BaseStream.Seek(-(35 * 800), SeekOrigin.End);
}
else
{//Go to start
FileReader.BaseStream.Seek(0, SeekOrigin.Begin);
}
string data;
string[] param;
string[] date;
do
{
data = FileReader.ReadLine();
Debug.Print(data);
param = data.Split(',');
date = param[0].Split('-', ' ', ':');
//altitudeGraph.Plot(double.Parse(param[1]), double.Parse(param[2]), (new DateTime(int.Parse(date[0]), int.Parse(date[1]), int.Parse(date[2]), int.Parse(date[3]), int.Parse(date[4]), int.Parse(date[5]))).ToString("H:mm:ss"));
}
while (FileReader.EndOfStream == false);
FileReader.Close();
}
The file is around 28KB big, and this code gets about halfway through, then throws this error on FileReader.ReadLine()
[quote] #### Exception System.IndexOutOfRangeException - 0xa9000000 (1) ####
#### Message:
#### System.IO.StreamReader::Peek [IP: 001c] ####
#### System.IO.StreamReader::ReadLine [IP: 005e] ####
#### HumidityGraph.Program::Main [IP: 006d] ####
A first chance exception of type ‘System.IndexOutOfRangeException’ occurred in System.IO.dll
An unhandled exception of type ‘System.IndexOutOfRangeException’ occurred in System.IO.dll[/quote]
Any Ideas?