I am a college student in an "introductory" to robotics course. At the beginning of the year we were told to buy a Netburner 5270 board. Throughout the year we learned some basic codes but now our final project is almost due and I am having an error. My code is pretty basic. I want it to first check if the pushbutton is pressed, if it is check if dipswitch1 is high, if it is then turn led1 on, turn servo (open door), and create-write a string- and close a text file onto my SD card. Everything works...70% of the time.
This is the function that should do everything I need for my SD card
void Enter_Door(char * FileName) {
iprintf("\r\nCreating file: %s\r\n", FileName);
int i = 0;
F_FILE* fp;
do {
fp = f_open( FileName, "a+" ); // Creating and Opening File
i++;
if (fp == 0) { /// Does NOT open
OSTimeDly(TICKS_PER_SECOND / 2);
}
} while (fp == 0 && i < 5);
if (fp == 0) {
iprintf("\r\n Error in Opening:%s\r\n", FileName);
} else {
const unsigned int write_buffer_size = 100;
char write_buf[write_buffer_size];
sniprintf(write_buf, write_buffer_size, "Person Entered at %ld seconds\r\n", Secs);
int n = f_write( write_buf, 1, strlen( write_buf ), fp );
iprintf("Wrote %d bytes: %s", n, write_buf);
iprintf("Closing file %s\r\n\r\n", FileName);
int rv = f_close( fp ); // Close a previously opened file of type F_FILE
do {
i++;
if (rv != 0) { /// Does NOT open
OSTimeDly(TICKS_PER_SECOND / 2);
}
} while (rv != 0 && i > 10);
if (rv != 0) {
f_close_PrintError(FileName);
DisplayEffsErrorCode(rv);
}
** the two do while loops in there I most recently added to try to redo the call, I am not sure if I wrote that write (again this is my first coding class)
My error occurs within the f_close function. I will push the pushbutton 10 times in a row and everything will work, but the 11th time I will get and error, but the 12th time it will work again? My typical errors are: * Error in f_close("Enter.txt") durring task(Main); F_ERR_NOTOPEN
or
* Error in f_close("Enter.txt") durring task(Main); F_ERR_WRITE
or
* Error in f_close("Enter.txt") durring task(Main); F_ERR_NOTFORMATED
Now like I said I do not get an error alot, but when I do it is one of those three. I really do not know whats going on or how to even attempt to fix it. This code is being written on NBeclipse. If anyone has any suggestions or tips I would really appreciate it.