Hi Guys,
I'm having a go at writing to a .txt file to a SD card in the Primer 2.
For the most part it seems to work, however every now and then i get a little glitch in the file.
Thought i would ask if:
1. Any thoughts on what could be causing the glitch?
2. Any suggestions for improvements to the code to stop the glitch from happening?
Please be gentle I'm a bit of a newb ![smile](img/smilies/smile.png)
Source (apologies for the parts blatently copied from others projects):
char data[13] = {"Hello World "};
...
MENU_code Application_Ini ()
{
data[11] = 0x0d;
data[12] = 0x0a;
StartMBR=FS_Mount(MMCSD_SDIO);
if (StartMBR == 0xFFFFFFFF)
{
DRAW_DisplayString(20,100,"No SDCARD",19);
}
if (FS_GetVolumeInfo(0, StartMBR, &volume_info))
{
DRAW_DisplayString(20,100,"\nErr: GetVolInfo",19);
}
if (FS_OpenDirectory(&volume_info, "", &directory_info))
{
DRAW_DisplayString(20,100,"\nErr: Open Root",19);
}
if(FS_OpenFile(&volume_info, "Data.txt", FS_WRITE, &file_info))
{
DRAW_DisplayString(20,100,"No File",19);
}
}
MENU_code Application_Handler ()
{
if ( BUTTON_GetState() != BUTTON_PUSHED )
{
if(FS_OpenFile(&volume_info, "Data.txt", FS_WRITE, &file_info))
{
DRAW_DisplayString(20,100,"No File",19);
}
FS_Seek(&file_info, (file_info.filelen));
if(FS_WriteFile(&file_info,data, &successcount,13))
{
DRAW_DisplayString(20,100,"Write Fail",19);
}
FS_Close(&file_info);
}
}
This produces a file Data.txt with the following content:
"Hello World
Hello World
Hello World
Hello World
Hello World
Hello World
Hello World
Hello World
Hello World
Hello World
Hello World
Hello World
Hello World
HeHello WorldHello World
Hello World
Hello World
Hello World
Hello World
Hello World
Hello World
Hello World
Hello World
Hello World
Hello World
Hello World
Hello World"
Last edited by DashboardDave (2009-07-26 10:27:27)