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,6 +1,10 @@
|
||||
import serial
|
||||
import pandas as pd
|
||||
|
||||
with serial.Serial('/dev/cu.usbserial-1420', 115200, timeout=1, parity=serial.PARITY_NONE) as ser:
|
||||
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
|
||||
@@ -21,7 +25,6 @@ with serial.Serial('/dev/cu.usbserial-1420', 115200, timeout=1, parity=serial.PA
|
||||
line = ser.readline()
|
||||
print(s)
|
||||
if 'Sample Completed' in s.decode("utf-8"):
|
||||
print("hi")
|
||||
ser.write(b'P')
|
||||
while True:
|
||||
x = ser.read()
|
||||
@@ -33,4 +36,8 @@ with serial.Serial('/dev/cu.usbserial-1420', 115200, timeout=1, parity=serial.PA
|
||||
break
|
||||
break
|
||||
break
|
||||
except serial.serialutil.SerialException:
|
||||
print("connect device!")
|
||||
except:
|
||||
print("error!")
|
||||
|
||||
Reference in New Issue
Block a user