Skip to content

Instantly share code, notes, and snippets.

@acspike
Last active December 31, 2015 20:29
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 acspike/8040133 to your computer and use it in GitHub Desktop.
Save acspike/8040133 to your computer and use it in GitHub Desktop.
import select
import serial
serial_dev = '/dev/ttyS1'
select_timeout = 30
port = serial.Serial(serial_dev, timeout=None)
port.flushInput()
data = ''
while True:
ready, _, _ = select.select([port],[],[], select_timeout)
# timeout reached
if not ready:
if data:
print "remaining data: " + repr(data)
data = ''
for fd in ready:
char = port.read(size=1)
if char == '\r':
print "received: " + repr(data)
data = ''
elif char!='':
data += char
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment