SdFatFile Class
SdFatFile Class
Description
A class for SD FAT File.
Syntax
class SdFatFile
Members
Public Constructors | |
SdFatFile::SdFatFile | Constructs a SdFatFile object. |
SdFatFile::~SdFatFile | Destructs a SdFatFile object. |
Public Methods | |
SdFatFile::write | Write content (1 byte or bytes) to the file. |
SdFatFile::read | Read content (1 byte or bytes) from the file. |
SdFatFile::peek | Read one byte from the file without moving the cursor. |
SdFatFile::available | Check if the cursor is at EOF (End-Of-File). |
SdFatFile::seek | Change cursor to a specific position. |
SdFatFile::close | Close file. |
SdFatFile::cursor_pos | Indicate the current cursor position. |
SdFatFile::file_size | Output the size of file (DWORDs). |
SdFatFile::write
Description
Write content (1 byte or bytes) to the file.
Syntax
virtual size_t write(uint8_t c);
virtual size_t write(const uint8_t *buf, size_t size);
Parameters
c: The character to be written.
buf: The buffer that stores the content to be written.
size: The length of buffer to be written.
Returns
This function returns the number of byte count that has been successfully written to the file.
Example Code
NA
Notes and Warnings
“SdFatFile.h” must be included to use the class function.
SdFatFile::read
Description
Read content (1 byte or bytes) from the file.
Syntax
virtual int read(void);
int read(void *buf, uint16_t nbyte);
Parameters
buf: The buffer that stores the content.
nbyte: The buffer size. (Or can be regarded as the desired length to read).
Returns
This function returns a read character or the size of the read buffer.
Example Code
Example: create_folder
(https://github.com/ambiot/ambd_arduino/blob/dev/Arduino_package/hardware/libraries/FatfsSDIO/examples/create_folder/create_folder.ino)
Notes and Warnings
“SdFatFile.h” must be included to use the class function.
SdFatFile::peek
Description
Read one byte from the file without moving the cursor.
Syntax
virtual int peek(void);
Parameters
NA
Returns
This function returns the read character as an integer number.
Example Code
NA
Notes and Warnings
“SdFatFile.h” must be included to use the class function.
SdFatFile::available
Description
Check if the cursor is at EOF.
Syntax
virtual int available(void);
Parameters
NA
Returns
This function returns “0” if the cursor is at EOF, else returns “1”.
Example Code
NA
Notes and Warnings
“SdFatFile.h” must be included to use the class function.
SdFatFile::seek
Description
Change cursor to a specific position.
Syntax
int seek(uint32_t pos);
Parameters
pos: The desired position.
Returns
This function returns 0 if the cursor is set a specific position successfully otherwise returns a negative value.
Example Code
NA
Notes and Warnings
“SdFatFile.h” must be included to use the class function.
SdFatFile::close
Description
Close file.
Syntax
int close(void);
Parameters
NA
Returns
This function returns 0 if file is closed successfully otherwise it returns a negative value.
Example Code
Example: create_folder
(https://github.com/ambiot/ambd_arduino/blob/dev/Arduino_package/hardware/libraries/FatfsSDIO/examples/create_folder/create_folder.ino)
Notes and Warnings
“SdFatFile.h” must be included to use the class function.
SdFatFile::cursor_pos
Description
Indicate the current cursor position. It is a file read/write pointer (Zeroed on file open).
Syntax
uint32_t cursor_pos (void);
Parameters
NA
Returns
This function returns a file read/write pointer. “0” on file open.
Example Code
NA
Notes and Warnings
“SdFatFile.h” must be included to use the class function.
SdFatFile::file_size
Description
Output the size of file (DWORDs).
Syntax
uint32_t file_size (void);
Parameters
NA
Returns
This function returns a DWORD value as the file size.
Example Code
NA
Notes and Warnings
“SdFatFile.h” must be included to use the class function.