Modifications

Sauter à la navigation Sauter à la recherche
1 091 octets ajoutés ,  20 mars 2022 à 00:04
aucun résumé de modification
Ligne 1 : Ligne 1 :  
{{ENG-CANSAT-PICO-NAV}}
 
{{ENG-CANSAT-PICO-NAV}}
   −
{{traduction}}
   
== MicroPython File System ==
 
== MicroPython File System ==
MicroPython board does fits an internal file system. This means that Python language on a MicroPython board can also manage files!
+
MicroPython board does fits an internal file system. This means that Python language on a MicroPython board can also manage files and directories! Exactly like python does on a computer :-).
    
[[Fichier:MicroPython-FileSystem.png|256px]]
 
[[Fichier:MicroPython-FileSystem.png|256px]]
Ligne 35 : Ligne 34 :     
=== Reading data from text file ===
 
=== Reading data from text file ===
{{traduction}}
+
The following script read the content of the "file2.txt" text file and displays it on the REPL output. 
   −
== File-system, Writing and data lost ==
+
<syntaxhighlight lang="python">
 +
with open( 'file2.txt', 'r' ) as _file:
 +
    s = _file.readline()
 +
    while s:
 +
        print( s.strip('\r\n') )
 +
        s = _file.readline()
 +
</syntaxhighlight>
 +
 
 +
Notes:
 +
* the file mode ''''r'''' used in the {{fname|open()}} reads text file.
 +
* the {{fname|readline()}} read and return a line from the file (including the carriage return & line feed.
 +
* the {{fname|strip('\r\n')}} remove the carriage return & line feed from the readed line. Otherwise it will also be printed to the REPL (which result into a double line feed).
 +
 
 +
== File-systems, Writing and data lost ==
    
{{underline|'''The computer file-system:'''}}
 
{{underline|'''The computer file-system:'''}}
Ligne 50 : Ligne 62 :     
{{underline|'''SD Card file system:'''}}
 
{{underline|'''SD Card file system:'''}}
 +
 +
[[Fichier:micro-sd.png|128px]]
    
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.
 
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.
Ligne 63 : Ligne 77 :  
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.  
 
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.
+
So, even if LittleFS do have minimal buffering, it is possible to force writing to the flash ( with {{fname|flush()}} ) to ensure minimal data lost in case of issue. So the user code can rely on better file-system stability and better control over forced writing operation.
    
The following example just {{fname|flush()}} writes at every line written to the file.  
 
The following example just {{fname|flush()}} writes at every line written to the file.  
Ligne 82 : Ligne 96 :     
[[Fichier:LittleFS-flushed.png|640px]]
 
[[Fichier:LittleFS-flushed.png|640px]]
 +
 +
== Ressources ==
 +
* [https://docs.micropython.org/en/latest/library/os.html Basic "operating system" services] (''micropython.org'')<br />Usual OS functions + file-system mounting, formating, block devices, etc
 +
* [https://docs.micropython.org/en/latest/reference/filesystem.html Working with filesystems] (micropython.org)
    
{{ENG-CANSAT-PICO-TRAILER}}
 
{{ENG-CANSAT-PICO-TRAILER}}
29 917

modifications

Menu de navigation