10000 tools: pyboard.py now acts as a command-line program to run scripts. · hellcoderz/micropython@3244123 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3244123

Browse files
committed
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.
1 parent aad1204 commit 3244123

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

tools/pyboard.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,18 @@
99
import pyboard
1010
pyb = pyboard.Pyboard('/dev/ttyACM0')
1111
pyb.enter_raw_repl()
12-
pyb.exec('pyb.Led(1).on()')
12+
pyb.exec('pyb.LED(1).on()')
1313
pyb.exit_raw_repl()
1414
1515
To run a script from the local machine on the board and print out the results:
1616
1717
import pyboard
1818
pyboard.execfile('test.py', device='/dev/ttyACM0')
1919
20+
This script can also be run directly. To execute a local script, use:
21+
22+
python pyboard.py test.py
23+
2024
"""
2125

2226
import time
@@ -157,5 +161,19 @@ def run_test():
157161
pyb.exit_raw_repl()
158162
pyb.close()
159163

164+
def main():
165+
import argparse
166+
cmd_parser = argparse.ArgumentParser(description='Run scripts on the pyboard.')
167+
cmd_parser.add_argument('--device', default='/dev/ttyACM0', help='the serial device of the pyboard')
168+
cmd_parser.add_argument('--test', action='store_true', help='run a small test suite on the pyboard')
169+
cmd_parser.add_argument('files', nargs='*', help='input files')
170+
args = cmd_parser.parse_args()
171+
172+
if args.test:
173+
run_test()
174+
175+
for file in args.files:
176+
execfile(file, device=args.device)
177+
160178
if __name__ == "__main__":
161-
run_test()
179+
main()

0 commit comments

Comments
 (0)
0