Hi again ;-)
some news...
After download the Simon's sample code, all works fine, why ? -> i used the old .cpp and .h files, now i import the SdFileSystem lib an it's fine.
I could test is an file exist or not even if the file is on subdir, great.
But i found a other issue when i want to write a file in a subdir. If my "isFileTest" test return false, i try to create a file on a subdir, and the mBed hang. If i try the same code in the root dir, all works fine (my original code write file only in the root dir).
I'm not sure it's an issue, but i find the "workaround".
If i try to create an new file in "append" mode in the root dir -> code is working, but if i try to do this in a subdir, the mBed hang.
I change my code to manage Append mode and Write mode, now i could create a new file in a sub file, i use Write mode to create it, after i could use Append mode to add data in my log file.
All works fine now with this "better" approach of file management on the SdCard.
Here my working code (trash and dirty for the moment sorry) :
#define WRITEFILE 1
#define APPENDFILE 2
/** ----------------------------------------------------------------------
* sdcardWriteFile
* Ecrit une trame dans le fichier specifie
* In : nom du fichier, mode d'ecriture, donnees a ecrire
* Out : true/false
* ---------------------------------------------------------------------*/
char sdcardWriteFile(const char *fileName, char mode, char *data)
{
FILE *fp2;
switch (mode)
{
case WRITEFILE :
fp2 = fopen(fileName, "w");
break;
case APPENDFILE :
fp2 = fopen(fileName, "a");
break;
default:
fp2 = fopen(fileName, "w");
}
if(!fp2)
{
return (false);
}
else
{
fprintf(fp2,data);
fclose(fp2);
}
return (true);
}
/** ----------------------------------------------------------------------
* sdcardIsFileExist
* Verifie si le fichier existe
* In : nom du fichier
* Out : true/false
* ---------------------------------------------------------------------*/
char sdcardIsFileExist(const char *fileName)
{
FILE *fp1 = fopen(fileName, "r");
if(!fp1)
{
return (false);
}
else
fclose(fp1);
return (true);
}
Thanks again Simon for your SDFileSystem lib !
Chris
If a SD card is plugged into the socket, I want to read a file from it, else I want to do something else
I thought that the 'if (fd)' in the following code would handle this, but if the card is not inserted it just sits there generating error messages. any ideas on how to fix this?
Minor Complaint: The terminal in Flash Magic (and some others) does not allow allow conversion of<LF> to <CR><LF> so the error messages form one continuous line that is very hard to read. Can someone find a few '\r' to add to the file system error messages?