Skip to content

Instantly share code, notes, and snippets.

@akarpenko
Created June 17, 2020 00:14
Show Gist options
  • Save akarpenko/f711e08b026598739afa83009dc24f47 to your computer and use it in GitHub Desktop.
Save akarpenko/f711e08b026598739afa83009dc24f47 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=4) as ser:
ser.write(b'\nsf probe\n')
print(ser.read(4000).decode())
ser.write(b'sf dump\n')
while True:
chunk = ser.read(512)
if not chunk:
break
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