-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcommandline.py
More file actions
executable file
·34 lines (28 loc) · 857 Bytes
/
commandline.py
File metadata and controls
executable file
·34 lines (28 loc) · 857 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python
import serial
import sys
RETURN = '\n'
# Connect to the Arduino
s = serial.Serial('/dev/ttyUSB1', 9600, timeout=60)
print "Connected to serial port. Use control^C or control^D to exit."
while True:
try:
input = raw_input("# ")
s.flushInput()
s.write(input + RETURN + RETURN)
got_return = False
while True:
try:
output = s.read()
if(output == RETURN):
if(got_return): break
got_return = True
else: got_return = False
sys.stdout.write(output)
except KeyboardInterrupt:
print "Interrupted by user"
break
except (KeyboardInterrupt, EOFError):
print "\nGot 'quit' from user. Bye!"
s.close()
sys.exit()