mirror of
https://github.com/g4klx/MMDVMHost
synced 2025-12-23 16:55:52 +08:00
Merge pull request #201 from phl0/nextion.py
Add proper error handling to nextion.py
This commit is contained in:
@@ -20,6 +20,7 @@ import serial
|
|||||||
import time
|
import time
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
|
|
||||||
e = "\xff\xff\xff"
|
e = "\xff\xff\xff"
|
||||||
|
|
||||||
@@ -105,9 +106,10 @@ if __name__ == "__main__":
|
|||||||
\nnote: model name is optional'
|
\nnote: model name is optional'
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
ser = serial.Serial(sys.argv[2], 9600, timeout=5)
|
try:
|
||||||
if not ser:
|
ser = serial.Serial(sys.argv[2], 9600, timeout=5)
|
||||||
print 'could not open device'
|
except serial.serialutil.SerialException:
|
||||||
|
print 'could not open serial device ' + sys.argv[2]
|
||||||
exit(1)
|
exit(1)
|
||||||
if not ser.is_open:
|
if not ser.is_open:
|
||||||
ser.open()
|
ser.open()
|
||||||
@@ -115,4 +117,8 @@ if __name__ == "__main__":
|
|||||||
checkModel = None
|
checkModel = None
|
||||||
if len(sys.argv) == 4:
|
if len(sys.argv) == 4:
|
||||||
checkModel = sys.argv[3]
|
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)
|
upload(ser, sys.argv[1], checkModel)
|
||||||
|
|||||||
Reference in New Issue
Block a user