Created Fri, 17 Aug 2012 15:32:43 +0000 by mikes
Fri, 17 Aug 2012 15:32:43 +0000
Is there a way to have more than one file open on a SD at one time?
I want to be able to open one file and while making some alterations write it's contents to another file.
Tue, 21 Aug 2012 23:24:57 +0000
Not with the standard SD library. Newer releases of the library supports this, but unfortunately they're not yet ported to Chipkit.
Tue, 04 Sep 2012 15:19:05 +0000
Ok I tried to port the new Arduino library to chipkit https://github.com/mskoczen/chipKIT32-MAX/tree/sd-1.0/hardware/pic32/libraries/SD It does work for multiple files but, it is slow running code like below takes about 7.5 seconds on a 378 byte file. That speed is acceptable for my purpose but I would not mind if it went a little faster, any suggestions appreciated.
File mainfile;
File tempfile;
mainfile = SD.open("FILE.TXT");
tempfile = SD.open("FILE2.TXT", FILE_WRITE);
char ch;
if (mainfile) {
while (mainfile.available()){//copy file
ch=mainfile.read();
tempfile.write(ch); //read one character out of file write to other
}
}
mainfile.close();
tempfile.close();
Tue, 04 Sep 2012 18:07:53 +0000
Great initiative and cool!
A couple of things (depending on the library defaults):
There are probably more things to check. (I guess you should check if tempfile exists as well before writing to it?)
Tue, 04 Sep 2012 21:40:23 +0000
Reading several chars then Writing them reduced the time to .3 seconds for the same file.
char n;
File mainfile;
File tempfile;
mainfile = SD.open(origname);
tempfile = SD.open(copyname, FILE_WRITE);
char ch[32];
if (mainfile) {
while (mainfile.available()){
for(n=0;n<32;n++)
ch[n]=mainfile.read();
for(n=0;n<32;n++)
tempfile.write(ch[n]);
}
}
mainfile.close();
tempfile.close();
Thu, 06 Sep 2012 11:42:52 +0000
You should be able to further improve by using the function that read/write calls directly, but with a larger array, i:e
Instead of: for (i < 32) read()
do: buf = read(32)
Same for writing.
The function resides in SdFat.h and looks as follows:
int16_t read(void) { //<----regular read()
uint8_t b;
return read(&b, 1) == 1 ? b : -1; //<--- does in fact point to a better function that reads multiple values in one go.
}
int16_t read(void* buf, uint16_t nbyte); //<---- needs to be accessible via the wrapper or made public (bad).
Sun, 28 Apr 2013 22:33:47 +0000
Just and update on this topic. The Arduino 1.0 SD features (that mikes back ported to 0023) to support multiple files open has been pulled into MPIDE and will be in the next release.
Jacob