Main Site Documentation

Saving data in SD


#1

Hi all! I’m working in an application that reads soma values through Serial port and process it. The program also saves all reads in a TXT file in SD.

By now, every time I have to write some data I execute this:

PersistentStorage sdPS = new PersistentStorage("SD");
sdPS.MountFileSystem();
...

If I receive data in a very short time, problem begin. I’ve seen that:
PersistentStorage sdPS = new PersistentStorage(“SD”); takes 1343ms
sdPS.MountFileSystem(); takes 483ms

I think, a solution can be do this only the first time I write something, instead of do it every time I write. In the other hand i think I can have some problems bacause of closing filesystem.

Can anyone help me??


#2

And why you mount storage everytime you open/write file? Do you on pc do same?
mount storage on application init and on insert sdcard and not everytime you write to file…


#3

The problem is that I don’t know where unmount file system. My app will be running everytime, only will stop running when I switch power off. In this case, file system won’t be closed and files will be corrupted…

This is why I am mounting-unmounting filesystem every time.


#4

You must FlushAll if you would like be shure that all data is written before you unmount card or reset system. You can flush data after each write and you are save if your device crash but for flush data you don’t need remount system… Check Documentation and some examples which write to USB or SD card…