Modifications

Sauter à la navigation Sauter à la recherche
1 143 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 13 : Ligne 12 :  
{{ambox|text=MicroPython file system (~100Kio) is not as large as a computer file system (10+ Gigabytes). Do not manipulate/write large amount of data on a MicroPython file-system.}}
 
{{ambox|text=MicroPython file system (~100Kio) is not as large as a computer file system (10+ Gigabytes). Do not manipulate/write large amount of data on a MicroPython file-system.}}
   −
== Data Logging on MicroPython ==
+
== Data Logging with MicroPython ==
 
Doing data logging with MicroPython is quite easy. You just open a file and write data into it like you will do with any Python code.
 
Doing data logging with MicroPython is quite easy. You just open a file and write data into it like you will do with any Python code.
   Ligne 34 : Ligne 33 :  
[[Fichier:ENG-CANSAT-PICO-LOG-10.png|480px]]
 
[[Fichier:ENG-CANSAT-PICO-LOG-10.png|480px]]
   −
=== File-system, Writing and data lost ===
+
=== Reading data from text file ===
 +
The following script read the content of the "file2.txt" text file and displays it on the REPL output. 
 +
 
 +
<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 47 : 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 60 : 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 79 : 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