Skip to content

Instantly share code, notes, and snippets.

@snegovick
Created December 3, 2012 09:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save snegovick/4193874 to your computer and use it in GitHub Desktop.
Save snegovick/4193874 to your computer and use it in GitHub Desktop.
simple script which reopens same tty
import serial
import struct
import sys
import time
def open_and_cat():
port = serial.Serial(sys.argv[1], sys.argv[2], bytesize=8, parity='N', stopbits=1, xonxoff=0, rtscts=0, timeout=2)
while True:
data = port.read(1)
if len(data)!=0:
sys.stdout.write(data)
sys.stdout.flush()
while True:
try:
open_and_cat()
except:
print "error on port, trying again"
time.sleep(0.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment