tools: pyboard.py now acts as a command-line program to run scripts.
You can run a local script on the pyboard using: python pyboard.py test.py where test.py is the local script you want to run.
This commit is contained in:
parent
aad1204b8e
commit
3244123031
|
@ -9,7 +9,7 @@ Example usage:
|
||||||
import pyboard
|
import pyboard
|
||||||
pyb = pyboard.Pyboard('/dev/ttyACM0')
|
pyb = pyboard.Pyboard('/dev/ttyACM0')
|
||||||
pyb.enter_raw_repl()
|
pyb.enter_raw_repl()
|
||||||
pyb.exec('pyb.Led(1).on()')
|
pyb.exec('pyb.LED(1).on()')
|
||||||
pyb.exit_raw_repl()
|
pyb.exit_raw_repl()
|
||||||
|
|
||||||
To run a script from the local machine on the board and print out the results:
|
To run a script from the local machine on the board and print out the results:
|
||||||
|
@ -17,6 +17,10 @@ To run a script from the local machine on the board and print out the results:
|
||||||
import pyboard
|
import pyboard
|
||||||
pyboard.execfile('test.py', device='/dev/ttyACM0')
|
pyboard.execfile('test.py', device='/dev/ttyACM0')
|
||||||
|
|
||||||
|
This script can also be run directly. To execute a local script, use:
|
||||||
|
|
||||||
|
python pyboard.py test.py
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
@ -157,5 +161,19 @@ def run_test():
|
||||||
pyb.exit_raw_repl()
|
pyb.exit_raw_repl()
|
||||||
pyb.close()
|
pyb.close()
|
||||||
|
|
||||||
|
def main():
|
||||||
|
import argparse
|
||||||
|
cmd_parser = argparse.ArgumentParser(description='Run scripts on the pyboard.')
|
||||||
|
cmd_parser.add_argument('--device', default='/dev/ttyACM0', help='the serial device of the pyboard')
|
||||||
|
cmd_parser.add_argument('--test', action='store_true', help='run a small test suite on the pyboard')
|
||||||
|
cmd_parser.add_argument('files', nargs='*', help='input files')
|
||||||
|
args = cmd_parser.parse_args()
|
||||||
|
|
||||||
|
if args.test:
|
||||||
|
run_test()
|
||||||
|
|
||||||
|
for file in args.files:
|
||||||
|
execfile(file, device=args.device)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
run_test()
|
main()
|
||||||
|
|
Loading…
Reference in New Issue