I have some problems with SDFat.
My goal is to have a global SdFile rulesFile; which i read from. To minimize the time it takes reading from the file, i want to keep the file open through the execution of the program.
But for some reason i cannot get it to work. If i explicitly open the file, read from the file and close it again, I'm getting the correct data. If I'm just opening the file in the end of Setup() and and I try to read from it, I'm not getting the right data.
I suspect that the file automatically closes for some reason.. Is there a way to keep a file open?
Code for reading which exists in a library .cpp file, it has access to the global rulesFile variable.
rulesFile.seekSet(0);
//Read the rule from the
rulesFile.read(&r, sizeof(Rule));
Serial.println(r.actions[0].duration);
This only works if I before the first line open the files, even though that i in the last line in the Setup() function calls
if(!rulesFile.open(rulesBufFileName, O_READ))
{
sd.errorHalt("Error open rules for read");
}
Thanks in advance