a. Open File

<< Click to Display Table of Contents >>

Navigation:  Tutorials > Tutorial 17 - CleO File System >

a. Open File

The FOpen() command is used to open a file.



Command Prototype


uint16_t FOpen(const char* String, int16_t Mode);





File name


Different modes to control file opening behavior. Refer to the table given below for various mode values and its description.





Refers to the read access to the object. Data can be read from the file


Opens the file. If the file does not exist, then this command fails


Refers to the write access to the object. Data can be written to the file


Creates a new file. If the file already exists then, this command fails


Creates a new file. If the file already exists, then it will be truncated and overwritten


It will open an existing file. If the file does not exist, then a new file will be created.






void setup()


 char STR1[] = "ABCDEFG";

 int16_t actual;


/* Initialize CleO - needs to be done only once */



/* Start building a screen frame */



 CleO.StringExt(FONT_MEDIUM, 160, 100, LIGHT_GREEN, TM, 0, 0,

 "Creating test.txt...");


 /* Open file for write */

int16_t f = CleO.FOpen("@test.txt", FILE_CREATE_ALWAYS | FILE_WRITE);


 CleO.StringExt(FONT_MEDIUM, 160, 240, LIGHT_GREEN, TM, 0, 0,

 "Writing ABCDEFG...");

/* Write into file */

 CleO.FWrite(f, strlen(STR1) + 1, (uint8_t*)STR1, actual);


 /* Print number of bytes written */

 char buf[30];

 sprintf(buf, "%d bytes written", actual);

 CleO.StringExt(FONT_MEDIUM, 160, 380, LIGHT_GREEN, TM, 0, 0, buf);


/* Close file using file handle */



/* Display completed screen frame */




void loop() { }





In the above code snippet, the code highlighted in yellow color shows how the file open operation is performed using the FOpen() command, by creating a test.txt file in SD card in the write mode. Once all transactions are completed, the file is closed using the FClose() command.


Use the @ symbol only when performing the file operation from the eFlash and not from the SD Card.