Skip to content

Instantly share code, notes, and snippets.

@akarpenko
Created June 16, 2020 22:59
Show Gist options
  • Save akarpenko/e714a8ebcb45644aaeddca8d6e642f33 to your computer and use it in GitHub Desktop.
Save akarpenko/e714a8ebcb45644aaeddca8d6e642f33 to your computer and use it in GitHub Desktop.
import serial
import sys
bytes_received = 0
with open("dump.bin", "wb") as f:
with serial.Serial('/dev/ttyUSB0', 500000, timeout=1) as ser:
ser.write(b'sf probe\n')
print(ser.read(1000))
ser.write(b'sf dump\n')
while chunk := ser.read(512):
f.write(chunk)
bytes_received += len(chunk)
percent_done = bytes_received / (64 * 1024 * 1024) * 100
sys.stdout.write(f"Received: {bytes_received} bytes {percent_done:.0f}%\r")
sys.stdout.flush()
sys.stdout.write("\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment