Skip to content
Snippets Groups Projects
Verified Commit 72424267 authored by fpletz's avatar fpletz :snowflake:
Browse files

feat(tools): add run.py to execute python files via serial

parent c3e34289
No related branches found
No related tags found
1 merge request!165feat(tools): add run.py to execute python files via serial
......@@ -22,6 +22,7 @@ in stdenv.mkDerivation rec {
ninja
py
py.pkgs.pillow
py.pkgs.pyserial
];
src = ./.;
buildCommand = ''
......
#!/usr/bin/env python3
# or using nix-shell
#!/usr/bin/env nix-shell
#! nix-shell -i python3 -p "python3.withPackages (ps: [ ps.pyserial ])"
import sys
import base64
import argparse
import serial
parser = argparse.ArgumentParser(description="Executes python scripts on card10")
parser.add_argument(
"script", type=argparse.FileType("r"), help="micropython file to execute"
)
parser.add_argument(
"-d",
"--device",
default="/dev/ttyACM0",
help="Serial device of the pycardium console",
)
args = parser.parse_args()
code = base64.b64encode(bytes(args.script.read(), "utf-8"))
with serial.Serial(port=args.device, baudrate=115200) as s:
s.write(b"\x03import ubinascii; exec(ubinascii.a2b_base64('" + code + b"'))\r\n")
s.readline()
s.readline()
line = ""
while not line.startswith(">>>"):
char = s.read().decode("utf-8")
if char == "\n":
print(line)
line = ""
else:
line += char
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment