#!/usr/bin/python import os import sys import serial DEF_FILE = 'main.bin' DEF_PORT = '/dev/ttyUSB0' if os.geteuid() != 0: print 'run me as root' sys.exit() if os.path.exists(DEF_FILE) == False: print 'failed to open {}'.format(DEF_FILE) sys.exit() print 'uploading...' ser = serial.Serial(DEF_PORT, 19200) ser.flush() f = open(DEF_FILE, 'rb') ser.write(f.read()) f.close() ser.close() print 'upload complete'