Merge pull request #201 from phl0/nextion.py
Add proper error handling to nextion.py
This commit is contained in:
commit
29a8f7fd94
1 changed files with 9 additions and 3 deletions
|
@ -20,6 +20,7 @@ import serial
|
|||
import time
|
||||
import sys
|
||||
import os
|
||||
import re
|
||||
|
||||
e = "\xff\xff\xff"
|
||||
|
||||
|
@ -105,9 +106,10 @@ if __name__ == "__main__":
|
|||
\nnote: model name is optional'
|
||||
exit(1)
|
||||
|
||||
ser = serial.Serial(sys.argv[2], 9600, timeout=5)
|
||||
if not ser:
|
||||
print 'could not open device'
|
||||
try:
|
||||
ser = serial.Serial(sys.argv[2], 9600, timeout=5)
|
||||
except serial.serialutil.SerialException:
|
||||
print 'could not open serial device ' + sys.argv[2]
|
||||
exit(1)
|
||||
if not ser.is_open:
|
||||
ser.open()
|
||||
|
@ -115,4 +117,8 @@ if __name__ == "__main__":
|
|||
checkModel = None
|
||||
if len(sys.argv) == 4:
|
||||
checkModel = sys.argv[3]
|
||||
pattern = re.compile("^NX\d{4}[TK]\d{3}$")
|
||||
if not pattern.match(checkModel):
|
||||
print 'Invalid model name. Please give a correct one (e.g. NX3224T024)'
|
||||
exit(1)
|
||||
upload(ser, sys.argv[1], checkModel)
|
||||
|
|
Loading…
Reference in a new issue