SWRU368C May 2018 – January 2021 CC3100 , CC3100MOD , CC3200 , CC3200MOD
This operation enables reading from an existing file. The purpose of the offset is mainly to allow random access read without using the fseek method as in "standard" file system. Using this method you can access any location in the file with a single API call.
_i32 sl_FsRead(_i32 FileHandle,
_u32 Offset,
_u8* pData,
_u32 Len);
Type | Parameter | In/Out | Description |
---|---|---|---|
_u32 | FileHandle | In | Handle to an existing file (returned on sl_FsOpen()) |
_u32 | Offset | In | Offset within a file |
_u32* | pData | In | Pointer to the written data |
_i32* | Len | in | Length of the written data |
On success, zero is returned. On error, an error code is returned.
_u8 DeviceFileName[] = "MyFile.txt";
_i32 DeviceFileHandle = -1;
_i32 RetVal;
_u8 ReadBuffer[100];
_u32 Offset;
Offset = 0;
RetVal = sl_FsOpen(DeviceFileName,
FS_MODE_OPEN_READ,
NULL,
&DeviceFileHandle);
RetVal = sl_FsRead( DeviceFileHandle,
Offset,
(_u8 *)ReadBuffer,
50);
Offset = 50;
RetVal = sl_FsWrite( DeviceFileHandle,
Offset,
(_u8 *)&ReadBuffer[50],
50);
RetVal = sl_FsClose(DeviceFileHandle,
NULL,
NULL,
NULL );
File appending is not embedded into the file system. Appending can be achieved by read-modify-write implementation in the host.