Modifications

Sauter à la navigation Sauter à la recherche
aucun résumé de modification
Ligne 34 : Ligne 34 :  
'''Attention: la commande {{fname|run}} n'est pas un shell ou un outil qui permet d'envoyer des entrées (données) depuis l'ordinateur vers la carte!''' Si vous avez besoin d'envoyer des entrées/données vers la carte alors vous aurez besoin de connecter la carte et [[FEATHER-CHARGER-MICROPYTHON-SERIAL-REPL|d'utiliser le REPL Série]].
 
'''Attention: la commande {{fname|run}} n'est pas un shell ou un outil qui permet d'envoyer des entrées (données) depuis l'ordinateur vers la carte!''' Si vous avez besoin d'envoyer des entrées/données vers la carte alors vous aurez besoin de connecter la carte et [[FEATHER-CHARGER-MICROPYTHON-SERIAL-REPL|d'utiliser le REPL Série]].
   −
{{traduction}}
+
Par défaut la commande {{fname|run}} attendra la fin d'exécution du script sur la carte avant d'afficher la sortie. Parfois, il arrive que vous n'ayez pas besoin de cette fonctionnalité --par exemple, lorsque votre script principal est une boucle infinie qui ne se termine jamais, auquel cas ampy attend indéfiniment la fin du script! Dans ce cas, ajoutez l'option '''--no-output''' à la commande {{fname|run}}. Ce flag/drapeau informe ampy qu'il ne doit pas attendre de sortie de la part du script et n'attend donc pas la fin d'exécution de celui-ci. Ampy exécute le script et rend la main immédiatement au terminal.
   −
By default the run command will wait for the script to finish running on the board before printing its output.  In some cases you don't want this behavior--for example if your script has a main or infinite loop that never returns you don't want ampy to sit around waiting forever for it to finish.  In this case add the '''--no-output''' option to the run command. This flag tells ampy not to wait for any output and instead just start running the script and return.
+
Par exemple: modifiez le script '''test.py''' de façon à ce qu'il fasse un comptage à l'intérieur d'une boucle infinie:
 
  −
For example modify the '''test.py''' script so that it counts numbers forever in an infinite loop:
      
  <syntaxhighlight lang="python">
 
  <syntaxhighlight lang="python">
Ligne 47 : Ligne 45 :  
     print(i)
 
     print(i)
 
     i += 1
 
     i += 1
     time.sleep(1.0)  # Delay for 1 second.
+
     time.sleep(1.0)  # attendre une seconde.
 
  </syntaxhighlight>
 
  </syntaxhighlight>
   −
Then run it with the '''--no-output''' option and notice it immediately returns:
+
Exécutez ensuite le script sur votre carte avec l'option '''--no-output'''. Comme vous pourrez le constater, ampy rend immédiatement la main au système d'exploitation:
    
  <nowiki>ampy --port /serial/port run --no-output test.py</nowiki>
 
  <nowiki>ampy --port /serial/port run --no-output test.py</nowiki>
   −
However open the board's serial REPL and watch it count numbers every second!
+
Vous pouvez néanmoins ouvrir une session REPL Série et voir le compte augmenter chaque seconde!
    
{{ADFImage|FEATHER-CHARGER-FICHIER-MICROPYTHON-RUNCODE-01.png}}
 
{{ADFImage|FEATHER-CHARGER-FICHIER-MICROPYTHON-RUNCODE-01.png}}
   −
Remember the program is still running, ampy just didn't wait for it to stop!
+
Gardez à l'esprit que le programme est toujours en cours d'exécution, ampy n'attend simplement pas qu'il se termine!
   −
The '''--no-output''' option is great for writing scripts that are like an Arduino sketch. In Arduino you have an explicit '''setup''' and '''loop''' function which you fill in with code that runs once (in '''setup''') and code that runs forever (in '''loop''').  MicroPython doesn't have exactly the same concept, but you can create it yourself in your own Python scripts!   
+
L'option '''--no-output''' est particulièrement approprié lorsque vous exécutez des scripts qui ressemblent au fonctionnement des croquis/sketch Arduino. {{traduction}} In Arduino you have an explicit '''setup''' and '''loop''' function which you fill in with code that runs once (in '''setup''') and code that runs forever (in '''loop''').  MicroPython doesn't have exactly the same concept, but you can create it yourself in your own Python scripts!   
    
In fact look at the '''test.py''' above and notice all the code before the '''while True''' loop is like the '''setup''' function from an Arduino sketch, it's executed just once at the start of the program.  Then the code inside the '''while True''' loop is like the '''loop''' function from Arduino, this code runs repeatedly as fast as possible.  To make it a little more clear here's the '''test.py''' with comments that show where the setup code goes and where the loop code goes:
 
In fact look at the '''test.py''' above and notice all the code before the '''while True''' loop is like the '''setup''' function from an Arduino sketch, it's executed just once at the start of the program.  Then the code inside the '''while True''' loop is like the '''loop''' function from Arduino, this code runs repeatedly as fast as possible.  To make it a little more clear here's the '''test.py''' with comments that show where the setup code goes and where the loop code goes:
29 917

modifications

Menu de navigation