SdFatFile Class

SdFatFile Class

Description
A class for SD FAT File.

Syntax
class SdFatFile

Members

Public Constructors 
SdFatFile::SdFatFileConstructs a SdFatFile object.
SdFatFile::~SdFatFileDestructs a SdFatFile object.
Public Methods 
SdFatFile::writeWrite content (1 byte or bytes) to the file.
SdFatFile::readRead content (1 byte or bytes) from the file.
SdFatFile::peekRead one byte from the file without moving the cursor.
SdFatFile::availableCheck if the cursor is at EOF (End-Of-File).
SdFatFile::seekChange cursor to a specific position.
SdFatFile::closeClose file.
SdFatFile::cursor_posIndicate the current cursor position.
SdFatFile::file_sizeOutput 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.

請先確認已安裝QQ通訊軟體