File_Close()
Close an Open File and Commit Changes
The File_Close() command is used to properly close an open file on the SD card, ensuring that all pending data in the file buffer is written to the SD card, file size and FAT clusters are updated, and the file handle is released. It is important to close a file before performing other file operations or removing the SD card.
Example:
File_Close()
Purpose:
• Commit Data: File_Close writes all of the buffered data to the file, updates the file size, and updates the File Allocation Table (FAT) clusters, ensuring that the changes are safely written to the SD card.
• File Integrity: This function ensures that no data is lost if the SD card is removed, as it writes all pending changes and synchronizes the file on the card.
How it Works:
1. Data Commit: Any buffered data that was written to the file is immediately written to the SD card.
2. File Size & FAT Update: The file size is updated, and the FAT clusters are recalculated to reflect the changes made to the file. This ensures that the SD card’s filesystem remains consistent.
3. File Closure: The file handle is released, making the file no longer accessible until it is opened again.
Key Notes:
• Disk Safety: Using File_Close() before removing the SD card ensures that the file’s data is safely written and the file is properly closed. This helps avoid corruption of the file if the SD card is removed while the file is still open.
• Mandatory Before New Operations: Before opening a new file, especially when writing, you must first close the current file. Failing to do so can cause issues with file handles and data integrity.
• Flush Before Removal: If you plan to remove the SD card, File_Close() guarantees the file is safe and that all writes have been completed.
TftSetUp(0) 'Set screen TftResetScreen(BLACK) 'Reset screen TftSetSndFont(0,0) 'Set Font0 While File_Init() <> cErrOK : Wend 'Initialize SD Card TftPrintSndString("Sd Initialization OK",1,0,0,1,GREEN,BLACK,0) 'Confirm Initialize SD Card File_TimeCreated(2,10,24,11,32,55) 'Set file created property While File_Create("pic.log") <> cErrOK : Wend 'Create pic.log TftPrintSndString("pic.log create OK",1,0,1,1,GREEN,BLACK,0) 'Confirm create Pic.log File_Close() 'Close pic.log While File_Create("PiC1.TxT") <> cErrOK : Wend 'Create PiC1.TxT TftPrintSndString("PiC1.TxT create OK",1,0,2,1,GREEN,BLACK,0) 'Confirm create PiC1.TxT File_Close() 'Close PiC1.TxT File_CreateDir("MyFolder") 'Create MyFolder directory TftPrintSndString("MyFolder create OK",1,0,3,1,GREEN,BLACK,0) 'Confirm create MyFolder File_CreateDir("Test") 'Create Test directory TftPrintSndString("Test create OK",1,0,4,1,GREEN,BLACK,0) 'Confirm create Test |
|
Created with the Personal Edition of HelpNDoc: Create cross-platform Qt Help files