26 lines
622 B
Python
26 lines
622 B
Python
|
#!/usr/bin/env python
|
||
|
|
||
|
# A daemon which should be able to run a script, as said by the
|
||
|
# connecting arduino
|
||
|
def get_tty(noinput = True):
|
||
|
# Get TTY
|
||
|
arduino_ports = []
|
||
|
while not arduino_ports:
|
||
|
arduino_ports = [
|
||
|
p.device
|
||
|
for p in serial.tools.list_ports.comports()
|
||
|
if 'Arduino' in p.description
|
||
|
]
|
||
|
if not arduino_ports:
|
||
|
raise IOError("No Arduino found")
|
||
|
|
||
|
if len(arduino_ports) > 1:
|
||
|
if noinput is True:
|
||
|
raise IOError("Too many Arduinos found")
|
||
|
else:
|
||
|
while tty not in arduino_ports:
|
||
|
tty = raw_input("Enter a tty: "+" ,".join(arduino_ports)+ ";")
|
||
|
|
||
|
else:
|
||
|
tty = arduino_ports[0]
|