Forums
Reading 2 files from $DISK at the program start - Printable Version

+- Forums (http://www.miupanel.com/forum)
+-- Forum: μPanel (http://www.miupanel.com/forum/forumdisplay.php?fid=1)
+--- Forum: File System and DISK (http://www.miupanel.com/forum/forumdisplay.php?fid=5)
+--- Thread: Reading 2 files from $DISK at the program start (/showthread.php?tid=221)



Reading 2 files from $DISK at the program start - jackjean - 07-03-2017

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.begin(57600);
 Serial2.println("");
 Serial2.println("$PING 200");
 Serial2.println("$FILE0:OPEN:temp.txt:r");
 Serial2.println("$FILE0:RA");
 Serial2.println("$FILE0:CLOSE");

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

  { 
    delay(1000);
   // 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  ...


RE: Reading 2 files from $DISK at the program start - Technomaker - 07-04-2017

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 = Serial2.read()) > '\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.


RE: Reading 2 files from $DISK at the program start - jackjean - 07-04-2017

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 :

Serial2.println("$FILE0:OPEN:temp.txt:r");
Serial2.println("$FILE0:RA");
Serial2.println("$FILE0:CLOSE");

Serial2.println("$FILE1:OPEN:time.txt:r");
Serial2.println("$FILE1:RA");
Serial2.println("$FILE1:CLOSE");

the Serial2.read in the loop being written like this :

int c;
 while ((c = Serial2.read()) > '\n') Msg += (char) c;
 if (c == '\n')
 {  
   delay(1000);
   Serial.println(Msg);
   Msg = "";   }

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

$OK-PING
$FILE0:OPEN: 29 bytes
$FILE0:>A:Temp135150170110180150180190

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 = Serial2.read()) > '\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 ????