Last active
December 31, 2015 20:29
-
-
Save acspike/8040133 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 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