Closed schirrel closed 8 years ago
// if (!myNewFile.open(root, filename, O_RDWR)) { // SERIAL_ECHO_START; // SERIAL_ECHOPGM(MSG_SD_CANT_ENTER_SUBDIR); // SERIAL_ECHOLN(filename); // } if (!myNewFile.open("teste.txt", O_CREAT | O_EXCL | O_WRITE)) {
Check the number of your parameters in myNewFile.open()
@Blue-Marlin
the number of parameters are
bool SdBaseFile::open(const char* path, uint8_t oflag) {
or are your saying about O_CREAT | O_EXCL | O_WRITE
?
Dear @CoderSquirrel what you commented
// if (!myNewFile.open(root, filename, O_RDWR)) {
has an other number of parameters.
With 2 parameter it would need a current wok directory (cwd_), but that is not set anywher.
@Blue-Marlin i understand npw, thanks i've tried now
void CardReader::write_new_file(char *buf, char* filename) {
SdFile myNewFile;
SdFile *parent = &root;
if (!myNewFile.open(*parent, "teste", O_CREAT | O_EXCL | O_WRITE)) {
SERIAL_ECHO_START;
SERIAL_ECHOPGM(MSG_SD_CANT_ENTER_SUBDIR);
SERIAL_ECHOLN("teste");
}
....
}
and got the same :
echo:Cannot enter subdir: teste Error:error writing to file
Think about objects and pointers to objects.
Is root
already initialised when you call write_new_file()
?
I initialize the card, open it and then i try to access it via my method, i tought that this way the root would already be setted.
I could make this work this way:
void CardReader::write_new_file(char *buf, char* filename) {
SdFile myNewFile;
curDir = &workDir;
if (!myNewFile.open(curDir, "arquivo.txt", O_CREAT | O_RDWR | O_EXCL | O_SYNC)) {
SERIAL_ECHOPGM(MSG_SD_CANT_ENTER_SUBDIR);
}
myNewFile.writeError = false;
myNewFile.print("1 2 3");
myNewFile.close();
if (myNewFile.writeError) {
SERIAL_ERROR_START;
SERIAL_ERRORLNPGM(MSG_SD_ERR_WRITE_TO_FILE);
}
}
as you said i needed to tell which directore i was, so i add curDir = &workDir;
but i notice a problem, i only can access it once i clicked at SD Menu option,
Thank you for your interest making Marlin better and reporting this issue but this topic has been open for a long period of time without any further development. Marlin has been under heavy development for the past couple of months and moving to it's last mile to finish the RC cycle and release Marlin v1.1.0. We suggest you to try out the latest RCBugfix branch and reopening this issue if required.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
I'm tring to save a file inside the SD in marlin, and i was searching about SdFat and Sd2Card. And then i saw this method insed marlin:
I tried to adapt it to my use based at the things i saw about sdfat:
But i always get error. if i use the filename, the first if, i got
if not i get
Do guys guys have done it before? OR What is the right way?