error handling and cors in api
This commit is contained in:
@@ -24,6 +24,21 @@ def consolidation(request):
|
||||
Response object using `make_response`
|
||||
<https://flask.palletsprojects.com/en/1.1.x/api/#flask.make_response>.
|
||||
"""
|
||||
|
||||
if request.method == 'OPTIONS':
|
||||
headers = {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': 'GET',
|
||||
'Access-Control-Allow-Headers': 'Content-Type',
|
||||
# 'Access-Control-Max-Age': '3600'
|
||||
}
|
||||
|
||||
return ('', 204, headers)
|
||||
|
||||
headers = {
|
||||
'Access-Control-Allow-Origin': '*'
|
||||
}
|
||||
|
||||
request_json = request.get_json(silent=True)
|
||||
request_args = request.args
|
||||
|
||||
|
||||
@@ -1,36 +1,43 @@
|
||||
import serial
|
||||
import pandas as pd
|
||||
|
||||
with serial.Serial('/dev/cu.usbserial-1420', 115200, timeout=1, parity=serial.PARITY_NONE) as ser:
|
||||
x = ser.read() # read one byte
|
||||
s = ser.read(10) # read up to ten bytes (timeout)
|
||||
line = ser.readline() # read a '\n' terminated line
|
||||
print(x)
|
||||
print(s)
|
||||
print(line)
|
||||
ser.write(b'B')
|
||||
while True:
|
||||
x = ser.read()
|
||||
b = ser.read(100)
|
||||
line = ser.readline()
|
||||
print(b)
|
||||
if 'Buffer Completed' in b.decode("utf-8"):
|
||||
ser.write(b'S')
|
||||
if __name__ == "__main__":
|
||||
|
||||
try:
|
||||
with serial.Serial('/dev/cu.usbserial-1420', 115200, timeout=1, parity=serial.PARITY_NONE) as ser:
|
||||
x = ser.read() # read one byte
|
||||
s = ser.read(10) # read up to ten bytes (timeout)
|
||||
line = ser.readline() # read a '\n' terminated line
|
||||
print(x)
|
||||
print(s)
|
||||
print(line)
|
||||
ser.write(b'B')
|
||||
while True:
|
||||
x = ser.read()
|
||||
s = ser.read(100)
|
||||
b = ser.read(100)
|
||||
line = ser.readline()
|
||||
print(s)
|
||||
if 'Sample Completed' in s.decode("utf-8"):
|
||||
print("hi")
|
||||
ser.write(b'P')
|
||||
print(b)
|
||||
if 'Buffer Completed' in b.decode("utf-8"):
|
||||
ser.write(b'S')
|
||||
while True:
|
||||
x = ser.read()
|
||||
r = ser.read(100)
|
||||
s = ser.read(100)
|
||||
line = ser.readline()
|
||||
print(r)
|
||||
if 'RESULT' in r.decode("utf-8") or 'REND' in r.decode('utf-8'):
|
||||
print(r)
|
||||
print(s)
|
||||
if 'Sample Completed' in s.decode("utf-8"):
|
||||
ser.write(b'P')
|
||||
while True:
|
||||
x = ser.read()
|
||||
r = ser.read(100)
|
||||
line = ser.readline()
|
||||
print(r)
|
||||
if 'RESULT' in r.decode("utf-8") or 'REND' in r.decode('utf-8'):
|
||||
print(r)
|
||||
break
|
||||
break
|
||||
break
|
||||
break
|
||||
except serial.serialutil.SerialException:
|
||||
print("connect device!")
|
||||
except:
|
||||
print("error!")
|
||||
|
||||
Reference in New Issue
Block a user