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():
|
def query_arduino():
|
||||||
global serial
|
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')
|
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.write(','.join(query))
|
||||||
fo.close()
|
fo.close()
|
||||||
|
|
||||||
|
@ -22,12 +25,12 @@ def print_arduino(pmode):
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
mode = argv
|
mode = argv
|
||||||
if mode[1] == 'temp':
|
try:
|
||||||
print_arduino(0)
|
if mode[1] == 'temp':
|
||||||
elif mode[1] == 'humid':
|
print_arduino(0)
|
||||||
print_arduino(1)
|
elif mode[1] == 'humid':
|
||||||
elif mode[1] == 'query':
|
print_arduino(1)
|
||||||
query_arduino()
|
elif mode[1] == 'query':
|
||||||
else:
|
query_arduino()
|
||||||
|
except IndexError:
|
||||||
print('Usage: script.py [temp] [humid]')
|
print('Usage: script.py [temp] [humid]')
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue