/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / read text file on SD card

Username:     
Password:     
             

Forum

# 1   2011-08-12 15:26:19 read text file on SD card

louis bonte
New member
Registered: 2010-05-28
Posts: 1

read text file on SD card

Hi,
In my Primer2 application, I would like to read simple parameters from a text file on an SD card (something like an INI file). No need to write to the file.
There would need to be only one file in the root of the SD card, given a simple name (e.g. parameters.txt)
The sequence would be like
Open File (for read) (equivalent to fp = fopen("/SD/parameters.txt", "r") )
Read file until EOF (equivalent to a loop with fgetc(fp) )
Close file (equivalent to fclose(fp) )
As I am new in the CircleOS and Primer, and I don't find my way in the documentation, it would be very helpful to have a simple example or some guidance on how to do.
Thanks a lot

Offline

 

# 2   2011-08-16 07:08:02 read text file on SD card

yrt
Administrator
From: Grenoble-France
Registered: 2008-06-11
Posts: 520
Website

Re: read text file on SD card

CircleOS provides API functions in order to manage files on the SD Card.
The principals are :
u32 FS_Mount(enum STORAGE_device device);
u32 FS_OpenFile(PVOLINFO volinfo, u8 *path, u8 mode, PFILEINFO fileinfo);
u32 FS_ReadFile(PFILEINFO fileinfo,  u8 *buffer, u32 *successcount, u32 len);
u32 FS_WriteFile(PFILEINFO fileinfo,  u8 *buffer, u32 *successcount, u32 len);
u32 FS_Close(PFILEINFO fileinfo);
void FS_Seek(PFILEINFO fileinfo, u32 offset);

Notice that files are always open in binary mode.

Take a look at the "FS_Explorer" function of the CircleOS, to see how to mount and run through the SDCard.

You can also find informations in the forum and examples in the project section.

Offline

 

Board footer