Modifications

Sauter à la navigation Sauter à la recherche
Ligne 51 : Ligne 51 :  
Voici un croquis qui vérifie la présence du fichier '''boot.py''' et affiche sont contenu (un caractère à la fois):
 
Voici un croquis qui vérifie la présence du fichier '''boot.py''' et affiche sont contenu (un caractère à la fois):
   −
<syntaxhighlight lang="python">
+
<syntaxhighlight lang="c">
   // Vérifie sir le fichier boot.py existe puis affiche le contenu.
+
   // Vérifie si le fichier boot.py existe puis affiche le contenu.
 
   if (pythonfs.exists("boot.py")) {
 
   if (pythonfs.exists("boot.py")) {
 
     File bootPy = pythonfs.open("boot.py", FILE_READ);
 
     File bootPy = pythonfs.open("boot.py", FILE_READ);
     Serial.println("Printing boot.py...");
+
     Serial.println("Afficher boot.py...");
 
     while (bootPy.available()) {
 
     while (bootPy.available()) {
 
       char c = bootPy.read();
 
       char c = bootPy.read();
Ligne 67 : Ligne 67 :  
</syntaxhighlight>
 
</syntaxhighlight>
   −
Notice the '''exists''' function is called to check if the boot.py file is found, and then the '''open''' function is used to open it in read mode.  Once a file is opened you'll get a reference to a File class object which you can read and write from as if it were a Serial device (again just like the SD card library, <a href="https://www.arduino.cc/en/Reference/SD">all of the same File class functions are available</a>).  In this case the '''available''' function will return the number of bytes left to read in the file, and the '''read''' function will read a character at a time to print it to the serial monitor.
+
Notez l'appel de la fonction '''exists''' qui vérifie la présence du fichier boot.py, puis l'utilisation de la fonction '''open''' pour ouvrir celui-ci en mode lecture (''read'' en anglais''). Une fois fichier ouvert vous obtenez une référence vers un objet de la classe File  qui permet de lire et écrire dans le fichier comme s'il s'agissait d'un périphérique Serial (encore une fois, [https://www.arduino.cc/en/Reference/SD toutes les fonctions de la classe File] sont identiques à celle de la classe carte SD).  
   −
Writing a file is just as easy, here's how the sketch writes to '''data.txt''':
+
Dans ce cas, la fonction '''available''' retournera le nombre d'octets (''bytes'') restant à lire jusqu'à la fin du fichier -et- la fonction '''read''' lit un caractère à la fois (pour l'afficher sur le moniteur série).
   −
<syntaxhighlight lang="python">
+
L'écriture d'un fichier est tout aussi simple, voici comment le croquis ajoute des données dans le fichier '''data.txt''':
   // Create or append to a data.txt file and add a new line
+
 
   // to the end of it. CircuitPython code can later open and
+
<syntaxhighlight lang="c">
   // see this file too!
+
   // Créer et ajouter des données dans le fichier data.txt  
 +
   // puis ajouter un retour à la ligne.
 +
  // Le code CircuitPython pourra, plus tard, ou consulter
 +
   // le contenu de ce fichier!
 
   File data = pythonfs.open("data.txt", FILE_WRITE);
 
   File data = pythonfs.open("data.txt", FILE_WRITE);
 
   if (data) {
 
   if (data) {
     // Write a new line to the file:
+
     // Ajouter une nouvelle ligne de donnée:
     data.println("Hello CircuitPython from Arduino!");
+
     data.println("Un bonjour a CircuitPython de la part d Arduino!");
 
     data.close();
 
     data.close();
     // See the other fatfs examples like fatfs_full_usage and fatfs_datalogging
+
     // Voir les autre exemples fatfs comme fatfs_full_usage  
     // for more examples of interacting with files.
+
    // et fatfs_datalogging pour plus d'exemples concernant
     Serial.println("Wrote a new line to the end of data.txt!");
+
     // les interactions avec les fichiers.
 +
     Serial.println("Nouvelle ligne ajoutée au fichier data.txt!");
 
   }
 
   }
 
   else {
 
   else {
     Serial.println("Error, failed to open data file for writing!");
+
     Serial.println("Erreur, ne sais pas ouvrir le fichier en écriture!");
 
   }
 
   }
 
</syntaxhighlight>
 
</syntaxhighlight>
29 917

modifications

Menu de navigation