Modifications

Sauter à la navigation Sauter à la recherche
2 379 octets ajoutés ,  8 mars 2022 à 00:09
Ligne 34 : Ligne 34 :  
[[Fichier:ENG-CANSAT-PICO-LOG-10.png|480px]]
 
[[Fichier:ENG-CANSAT-PICO-LOG-10.png|480px]]
   −
=== Writing and data lost ===
+
=== File-system, Writing and data lost ===
xxxx
      +
{{underline|'''The computer file-system:'''}}
 +
 +
When working with file on a computer it is essential (even critial) to close the file to be ensured that all data are written to the file-system.
 +
 +
Ensuring good performance on a computer do involves lot buffering mechanism at software and hardware levels.
 +
 +
Cutting the power on a computer usually results into missing data or corrupted files.
 +
 +
Note: this is not true for databases which ensure and 200% the log file writing before applying changes to the database.
 +
 +
{{underline|'''SD Card file system:'''}}
 +
 +
Regardless of the platform using the SD card, the content and stability of a SD card is veryyyyyyy sensitive to the open/close operation on the file-system. Users of the Raspberry-Pi nano computer knows that powering of a Pi during SD write operation could completely corrupt the file-system. In some rare situation the SD card can be made completely unreadable.
 +
 +
Using SD-Card with microcontroler is not recommended when writing operation are involved. Using SD in write mode implies electronic skills to spare some "emergency power" for closing files on the SD card before the final shutdown.
 +
 +
{{underline|'''MicroPython file-system:'''}}
 +
 +
The since MicroPython 1.12 (2019), the file-system is based on LittleFS.
 +
 +
[[Fichier:LittleFS.png]]
 +
 +
LittleFS is a flash-based device filesystem. It has been designed to be more resistant to filesystem corruption and power failures resilient. Unless other file-systems, the RAM used by LittleFS does not depend on the file-system size (it is said "RAM bounded" without RAM allocation overflow). See [https://github.com/littlefs-project/littlefs LittleFS Github] for more information.
 +
 +
So, even if LittleFS do have some minimal buffering, it is possible to force writing to the flah ( with {{fname|flush()}} ). So the user code can rely on better file-system stability and better control over forced writing operation.
 +
 +
<syntaxhighlight lang="python">
 +
import time
 +
with open( 'file2.txt', 'a' ) as _file:
 +
    for i in range( 50 ):
 +
        print( i )
 +
        _file.write( 'Hey, it is MicroPython %i\r\n' % i )
 +
        _file.flush() # Force writing operation
 +
        time.sleep( 1 )
 +
</syntaxhighlight>
 +
 +
{{underline|Please note:}} abusing the {{fname|flush()}} operation will slow down the code and will degrade flash faster (Flash Memory cells do have a maximum write cycles).
    
{{ENG-CANSAT-PICO-TRAILER}}
 
{{ENG-CANSAT-PICO-TRAILER}}
29 917

modifications

Menu de navigation