diff --git a/cloud-functions/python/functions/consolidation.py b/cloud-functions/python/functions/consolidation.py index 3bb64e4..7b068cd 100644 --- a/cloud-functions/python/functions/consolidation.py +++ b/cloud-functions/python/functions/consolidation.py @@ -24,6 +24,21 @@ def consolidation(request): Response object using `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 diff --git a/scripts/serial_qc.py b/scripts/serial_qc.py index 7b8daff..adec88c 100644 --- a/scripts/serial_qc.py +++ b/scripts/serial_qc.py @@ -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!") \ No newline at end of file