Offline
Newbie
Karma: 0
Posts: 24
|
 |
« on: September 23, 2011, 05:40:10 pm » |
I've looked through the SD library for IDE 0022 but did not see a function which renames the file on the SD card. Does anybody know how to rename SD card files or if there is another library out there which can?
I'm wanting to keep the last full day's data onto the SD card, always calling it yesturda.csv
So, when there is yesturda.csv with 24 hrs of data, then I create now.csv to start writing the next day's data. When now.csv fills up 24 hours with of data, then I'll want to delete yesturda.csv and rename now.csv to yesturda.csv. The next 24 hours starts again with a new now.csv.
As you can see, all I need is a file rename command. Any ideas? Thanks.
|
|
|
|
|
Logged
|
|
|
|
|
Netherlands
Offline
Sr. Member
Karma: 2
Posts: 433
A naughty mind is a joy forever.
|
 |
« Reply #1 on: September 23, 2011, 07:20:26 pm » |
Haven't looked into the standard library very much yet, but I do know the SDFat library renames files perfectly. I think it's a great piece of work. http://code.google.com/p/sdfatlib/
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 24
|
 |
« Reply #2 on: September 23, 2011, 07:39:26 pm » |
I've already written my cude using the standard SD library and was noping not to change all the syntax for SdFat. Does anyone know how to add the rename feature from SdFAT into the standard SD library?
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Edison Member
Karma: 28
Posts: 1079
Arduino rocks
|
 |
« Reply #3 on: September 23, 2011, 09:12:58 pm » |
There is no practical way to add rename to SD.h. SD.h is a wrapper for an old version of SdFat that does not support rename.
The newer SdFat with rename can't be used with the SD.h wrapper.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 24
|
 |
« Reply #4 on: September 23, 2011, 09:57:08 pm » |
This is unfortunate. Does anybody know when an updated IDE-standard SD library will exist with a rename feature? Does anybody know the equivalent of this SD code using SdFat? //if logfile.txt doesn't exist, SD.open creates a new file, if it exists, it appends data to it File dataFile = SD.open("logfile.txt", FILE_WRITE); if (dataFile) { // If the file is available, write to it dataFile.println("Hello"); dataFile.close(); } How do I create this same functionality from SdFat? Also, what is the equivalent of, if (SD.exists("now.csv")) ?
|
|
|
|
« Last Edit: September 23, 2011, 10:02:01 pm by feipoa »
|
Logged
|
|
|
|
|
0
Offline
Edison Member
Karma: 28
Posts: 1079
Arduino rocks
|
 |
« Reply #5 on: September 23, 2011, 10:16:20 pm » |
To open or create a file for append in SdFat if (datafile.open("logfile.txt", O_WRITE | O_CREAT | O_APPEND)) { dataFile.println("Hello"); dataFile.close(); }
If you declared SdFat sd; use if (sd.exists("now.csv"))
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 24
|
 |
« Reply #6 on: September 23, 2011, 10:29:56 pm » |
When I do that I get,
error: 'class Sd2Card' has no member named 'exists'
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Edison Member
Karma: 28
Posts: 1079
Arduino rocks
|
 |
« Reply #7 on: September 23, 2011, 10:34:52 pm » |
I said esists() is a member of the class SdFat, not Sd2Card.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 24
|
 |
« Reply #8 on: September 23, 2011, 10:38:57 pm » |
I'm not sure I follow. I am including SdFat.h already. What else do I need to include to get exists() to function? EDIT: The last features I need for the transition from SD to SdFat is the equivalent of this, if (card.exists("now.csv")) { now.remove("now.csv"); }
|
|
|
|
« Last Edit: September 23, 2011, 10:43:58 pm by feipoa »
|
Logged
|
|
|
|
|
0
Offline
Edison Member
Karma: 28
Posts: 1079
Arduino rocks
|
 |
« Reply #9 on: September 23, 2011, 10:43:12 pm » |
Read the html documentation and look at examples.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 24
|
 |
« Reply #10 on: September 23, 2011, 10:51:01 pm » |
The documentation is horrific.
Maybe somebody else here would like to exercise their skills of generocity?
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Edison Member
Karma: 28
Posts: 1079
Arduino rocks
|
 |
« Reply #11 on: September 23, 2011, 11:01:25 pm » |
O.K. here is a sketch that checks for "myfile.txt". #include <SdFat.h> SdFat sd; const uint8_t CHIP_SELECT = 10; // pin 10 is SD chip select void setup() { Serial.begin(9600); if (!sd.init(SPI_HALF_SPEED, CHIP_SELECT)) sd.initErrorHalt(); if (sd.exists("myfile.txt")) Serial.println("it exists"); } void loop() {}
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 24
|
 |
« Reply #12 on: September 24, 2011, 01:50:50 am » |
Thank you for sharing this information. I now see what you mean by the SdFat class. I had "sd" as part of another class in my code.
While I can use the SdFat lib code to perform all my desired SD writing needs (in stand-alone sketches), it seems when I integrate it with all my other code the SD card isn't being written to. It is probably not initializing at all.
I'm at a 25000 byte sketch size and am constantly trying to optimise code to save SRAM space. Any new additions I make often set the Arduino into a resetting mode (implying I'm out of SRAM space), so I suspect that using SdFat over the SD class caused me to run out of SRAM.
Has there been any development towards introducing a renaming feature into the next IDE release for the SD class?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 24
|
 |
« Reply #13 on: September 24, 2011, 03:12:51 am » |
Maybe there is another way to accomplish what I want with just the 0022 SD library.
As I mentioned, I'm wanting to keep the last full day's worth data onto the SD card, always calling it yesturda.csv
So, when there is yesturda.csv with 24 hrs of data, then I create now.csv to start writing the next day's data. When now.csv fills up 24 hours with of data, then I'll want to delete yesturda.csv and rename now.csv to yesturda.csv. The next 24 hours starts again with a new now.csv.
Is there another way to always have yesturday's data on a static filename? Thanks.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Edison Member
Karma: 28
Posts: 1079
Arduino rocks
|
 |
« Reply #14 on: September 24, 2011, 07:27:29 am » |
SD.h will not have rename anytime soon. In Arduino 1.0 SD.h will be about two KB larger than the new SdFat and use more RAM. You can do anything SD.h does with SdFat since SD.h is a simple wrapper for an old version of SdFat. The SD.h wrapper mainly changes the default behavior for open(), and uses a different syntax for the API. SD.h opens files so sync/flush is called after every write()/print(). This is very slow but insures data is written to the SD. Also SD.h positions files opened for write at EOF. Try opening your file with the flags in this sketch: #include <SdFat.h> #include <SdFatUtil.h> SdFat sd;
SdFile logfile;
// open like SD.h const uint8_t OPEN_FLAGS = O_RDWR | O_CREAT | O_SYNC | O_AT_END;
const uint8_t SD_CHIP_SELECT = 10;
#define error(msg) sd.errorHalt_P(PSTR(msg))
void setup() { Serial.begin(9600); Serial.println("type any character to start"); while (Serial.read() < 0); // initialize SdFat if (!sd.init(SPI_FULL_SPEED, SD_CHIP_SELECT)) sd.initErrorHalt(); // use SD.h style flags if (!logfile.open("now.csv", OPEN_FLAGS)) error("open"); // add a line to file logfile.println("line added to logfile"); // skip sync and close to prove data is saved Serial.println("Done"); } void loop() {}
|
|
|
|
|
Logged
|
|
|
|
|
|