Files
hpos-data/scripts/serial_qc.py

83 lines
3.3 KiB
Python
Raw Normal View History

2023-08-23 19:19:54 +05:30
import serial
2023-08-23 20:07:48 +05:30
import pandas as pd
2023-08-24 09:33:52 +05:30
import os.path
from datetime import datetime
import math
import time
from tqdm import tqdm
2023-08-23 19:19:54 +05:30
2023-08-24 09:33:52 +05:30
class Device:
def __init__(self, accuracy, precision):
self.accuracy = accuracy
self.precision = precision
2023-08-23 20:07:48 +05:30
2023-08-24 09:33:52 +05:30
def perform_hpos_test(repeat_no):
2023-08-23 20:07:48 +05:30
try:
2023-08-24 09:33:52 +05:30
data_file = 'data.xlsx'
if os.path.exists(data_file):
df = pd.read_excel('data.xlsx')
else:
df = pd.DataFrame(columns=["sol", "427_buffer_intensity", "555_buffer_intensity", "427_sample_intensity", "555_sample_intensity", "427_absorbance", "555_absorbance", "absorbance_ratio", "time"])
time.sleep(5)
2023-08-23 20:07:48 +05:30
with serial.Serial('/dev/cu.usbserial-1420', 115200, timeout=1, parity=serial.PARITY_NONE) as ser:
2023-08-24 09:33:52 +05:30
x = ser.read()
s = ser.read(10)
line = ser.readline()
2023-08-23 20:07:48 +05:30
print(x)
print(s)
print(line)
2023-08-24 09:33:52 +05:30
# perform_blanking = input("Do you want to perform blanking?(Y/N)")
2023-08-23 20:07:48 +05:30
ser.write(b'B')
2023-08-23 19:19:54 +05:30
while True:
x = ser.read()
2023-08-23 20:07:48 +05:30
b = ser.read(100)
2023-08-23 19:19:54 +05:30
line = ser.readline()
2023-08-23 20:07:48 +05:30
print(b)
if 'Buffer Completed' in b.decode("utf-8"):
ser.write(b'S')
2023-08-23 19:19:54 +05:30
while True:
x = ser.read()
2023-08-23 20:07:48 +05:30
s = ser.read(100)
2023-08-23 19:19:54 +05:30
line = ser.readline()
2023-08-23 20:07:48 +05:30
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'):
2023-08-24 09:33:52 +05:30
result = r.decode("utf-8").split(' ')
df = pd.concat([df, pd.DataFrame([{"sol": solution + '-' + str(repeat_no), "427_buffer_intensity": result[3], "555_buffer_intensity": result[3], "427_sample_intensity": result[5], "555_sample_intensity": result[6], "427_absorbance": math.log10(float(result[3]) / float(result[5])), "555_absorbance": math.log10(float(result[4]) / float(result[6])), "absorbance_ratio": math.log10(float(result[3]) / float(result[5])) / math.log10(float(result[4]) / float(result[6])), "time": datetime.today().strftime('%d-%m-%y %H:%M:%S')}])], ignore_index = True)
print(df)
writer = pd.ExcelWriter(data_file, engine = 'openpyxl')
df.to_excel(writer, sheet_name = 'data', index=False)
writer.close()
2023-08-23 20:07:48 +05:30
break
2023-08-23 19:19:54 +05:30
break
break
2023-08-24 09:33:52 +05:30
2023-08-23 20:07:48 +05:30
except serial.serialutil.SerialException:
2023-08-24 09:33:52 +05:30
print("device is not connected!")
exit()
except Exception as err:
print("error!", err)
exit()
if __name__ == "__main__":
d = Device(0.01, 0.001)
solution = input("solution name: ")
repeats = int(input("number of repeats: "))
for repeat in tqdm(range(0, repeats)):
perform_hpos_test(repeat)
2023-08-23 19:19:54 +05:30