Created
June 16, 2020 22:59
-
-
Save akarpenko/e714a8ebcb45644aaeddca8d6e642f33 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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