Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Reading 2 files from $DISK at the program start
Hi eveybody,
I am working on a project with some variables that must be saved on the $DISK of the SCF01 (like tempetaures and times).
These values must be re-loaded at the next start following each power fail.
My data must be stored in 2 separate files : one for the Temperatures (temp.txt) and one for the Times (time.txt).
Writing the data into both files is OK (tested by reading the content of both files).
Le problem is that I do not find the way to restore these data from the both files to the Sketch.
For one file, it is OK :
in the setup :

 Serial2.println("$PING 200");

and in the loop :
  while ((c = > '\n') Msg += (char) c;
  if (c == '\n')                                 

   // From the string "Msg" are extracted the values to be restored, than :
    Msg = "";

 Since the file is opened in the Setup and read in the loop, how can I proceed to do the transfert from the second file ???

Thank you for your support  ...
Hi jackjean,
if I well understood, you need to read the 2 files only at start to restore the old data.
I think you have should "open>read>close" both files (once for time) in setup, putting also the "while ((c = > '\n') ....." routine in setup.

Note that the RX buffer of arduino is 64 bytes so, if you want to read all data in once time, the sum of two file must be less than 65 bytes otherwise you lose data.
Hi Technomaker, and thanks for your quick reply.
You have perfectly understood.
Of course, these files are opened again for writing (and closed) along the sketch when the values have to be changed (Temp and /or Time).
As you can see in my first post, I have opened temp.txt for reading, read, and close in the setup.
If I add the same for the file time.txt , like this :



the in the loop being written like this :

int c;
 while ((c = > '\n') Msg += (char) c;
 if (c == '\n')
   Msg = "";   }

the response is only the content of the first file (temp.txt) as shown hereunder :

$FILE0:OPEN: 29 bytes

note : the characters "Temp" are also stored in head of values, in order to check if we read the right file.

Questions : why the content of the time.txt is not returned as a second line or something like ??
Must I append both files in one ? Ihave tried that, but with 57 bytes, the file does not be written (also strange...)

uupppsss... I have not noticed that you ask for writing also the "...while ((c = > '\n') Msg += (char) c;... in the setup.

I did not that, because i thought that the setup is read only once, and the "while" loop needs as many loops as amount of characters to read... no ????

Forum Jump:

Users browsing this thread: 1 Guest(s)