Skip to content

Instantly share code, notes, and snippets.

@akarpenko
Created June 17, 2020 04:48
Show Gist options
  • Save akarpenko/f6ab909c0497679d86b9c33502347895 to your computer and use it in GitHub Desktop.
Save akarpenko/f6ab909c0497679d86b9c33502347895 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import serial
import sys
from xmodem import XMODEM
# Setup:
# pip install pyserial
# pip install xmodem
ser = serial.Serial('/dev/ttyUSB0', timeout=0) # or whatever port you need
def getc(size, timeout=1):
return ser.read(size) or None
def putc(data, timeout=1):
return ser.write(data) # note that this ignores the timeout
modem = XMODEM(getc, putc)
with open(sys.argv[1], "rb") as f:
modem.send(f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment