catch the serial exception and force zeroes
This commit is contained in:
parent
c433d24b9b
commit
887591113e
1 changed files with 14 additions and 11 deletions
|
@ -7,10 +7,13 @@ from sys import argv
|
|||
|
||||
def query_arduino():
|
||||
global serial
|
||||
serial = serial.Serial('/dev/ttyACM0', 9600)
|
||||
serial.write('1')
|
||||
query = serial.readline().strip('\r\n').split()
|
||||
fo = open('/etc/scripts/.arduino.db', 'wb')
|
||||
try:
|
||||
serial = serial.Serial('/dev/ttyACM0', 9600)
|
||||
serial.write('1')
|
||||
query = serial.readline().strip('\r\n').split()
|
||||
except:
|
||||
query = ("0", "0")
|
||||
fo.write(','.join(query))
|
||||
fo.close()
|
||||
|
||||
|
@ -22,12 +25,12 @@ def print_arduino(pmode):
|
|||
|
||||
if __name__ == "__main__":
|
||||
mode = argv
|
||||
if mode[1] == 'temp':
|
||||
print_arduino(0)
|
||||
elif mode[1] == 'humid':
|
||||
print_arduino(1)
|
||||
elif mode[1] == 'query':
|
||||
query_arduino()
|
||||
else:
|
||||
try:
|
||||
if mode[1] == 'temp':
|
||||
print_arduino(0)
|
||||
elif mode[1] == 'humid':
|
||||
print_arduino(1)
|
||||
elif mode[1] == 'query':
|
||||
query_arduino()
|
||||
except IndexError:
|
||||
print('Usage: script.py [temp] [humid]')
|
||||
|
||||
|
|
Loading…
Reference in a new issue